【发布时间】:2017-10-05 17:23:14
【问题描述】:
我知道我们可以像这样使用主题变量:
const Button = styled.button`
cursor: pointer;
border-radius: ${props => props.theme.borderRadiusSize};
dir: ${props => props.theme.dir}
outline: none;
`;
上面的工作。我需要做的不仅仅是改变风格,还有一些主题变量。 例如:
if (theme.dir === 'rtl')
do some stuff more in render!
我尝试使用来自props 的theme 对象,如下所示:
const {theme} = this.props;
if (theme.dir === 'rtl')
do some stuff more in render!
但是theme 属性是未定义的。
我可以使用从父<ThemeProvider/> 传递的theme 对象吗?我不想使用全局状态。
【问题讨论】:
标签: reactjs themes styled-components