找不到一個清晰的例子,如何在 .css 對象中使用函數styled-components。它不會引發錯誤,但在提取道具時不會將背景添加到 CSS 輸出中,如下例所示。// Simple color functionconst color = (error) => { if (error) { return 'red' } return 'black',}作品- cssconst StyledInput = styled.input<InputProps>` background: ${({ error }) => color(error)};`;工作- css 對象const StyledInput = styled.input<InputProps>(props => ({ background: color(), // !!! NEED error from props}));不工作- css 對象const StyledInput = styled.input<InputProps>(props => ({ background: `${({ error }) => color(error)}`,}));
樣式化組件在樣式化對象中使用函數
瀟瀟雨雨
2022-06-09 17:14:34