【发布时间】:2019-05-31 03:41:19
【问题描述】:
出于好奇,我在我的 React 应用程序中使用样式化组件,并在其中使用建议的主题来让所有颜色和大小都可用。
目前我正在这样做:
export const TestComponent = styled.div`
color: ${({ theme }) => theme.white};
background-color: ${({ theme }) => theme.white};
border: 1px solid ${({ theme }) => theme.white};
display: ${({ check }) => check ? 'block' : 'none'};
`;
所以我正在使用来自ThemeProvider 的主题,并且还额外检查了外部组件。
我现在的问题是,为什么不能这样使用:
export const TestComponent = styled.div`${({ theme, check }) => (css`
color: ${theme.white};
background-color: ${theme.white};
border: 1px solid ${theme.white};
display: ${check ? 'block' : 'none'};
`)`;
岂不是更方便、更容易使用?如果是这样,他们为什么不这样建议呢?我只是害怕它有一些我现在看不到的巨大缺点。
【问题讨论】:
标签: css reactjs sass styled-components emotion