【发布时间】:2021-06-23 08:41:27
【问题描述】:
我只想在一个 React 组件中从 theme.scss 更改下面显示的 Sass 变量的值。
主题.scss
$backgroundColor: #fff;
$secondaryColor: #000;
反应组件
useEffect(() => {
// i want to change the Sass variable here inside this hook
// so that when the state changes the color changes
}, [state])
【问题讨论】:
-
你不能动态改变 SASS 变量,一旦样式被编译,变量就不再存在了。您应该改用CSS variables。
-
在 Sass 函数中使用 css 变量时出现错误。SassError: argument
$colorofdarken($color, $amount)must be a color on line 39 of F:\Projects\REACT PROJECTS\react\src \Screens\HomeScreen.scss,在函数darken中来自 stdin >> 的第 39 行背景:darken(var(--primary-color), 3);
标签: reactjs sass use-effect