出于好奇,我在我的 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'};
`)`;
使用起来不是更方便、更容易吗?如果是这样,他们为什么不这样建议呢?我只是害怕它有一些我现在看不到的巨大缺点。