首先,我对React相当陌生,所以我仍然在学习我的方法。在React中使用情绪CSS-in-JS与主题
我在使用Themes和Emotion设置Introduction Article (Medium.com)。但我坚持试图将内compose
例如使用一个const使用主题颜色,我有:
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]};
`);
(这是一个人为的例子在现实中,我如果我渲染<Button type="primary">A Button</Button>
,则颜色不会被应用。事实上,如果我检查元素,我甚至不会看到color
样式。
但是,如果不是我改变Button
到:
const Button = withTheme(styled.button`
composes: ${types.primary};
`);
然后我看到应用了正确的颜色。
我不完全确定我在这里做错了什么。