首先,我对 React 还很陌生,所以我还在学习。
我正在关注关于设置使用Themes with Emotion的介绍文章 (Medium.com)。但我坚持尝试在 const 中使用主题颜色,该主题颜色将在compose
例如,我有:
const types = {
primary: (props) => css`color: ${props.theme.blue}`,
secondary: (props) => css`color: ${props.theme.red}`
};
const Button = withTheme(styled.button`
composes: ${props => types[props.type]};
`);
(这是一个人为的例子。实际上,我的primary
和secondary
将会有更多的 CSS。)
如果我 render <Button type="primary">A Button</Button>
,颜色不会被应用。事实上,如果我检查元素,我什至看不到color
样式。
但是,如果改为Button
:
const Button = withTheme(styled.button`
composes: ${types.primary};
`);
然后我看到应用了正确的颜色。
我不完全确定我在这里做错了什么。