LoginSignup
4
1

More than 3 years have passed since last update.

ReactでSCSSの変数をimportする

Posted at

概要

Reactでscss moduleを扱うとき、scss内で定義した変数をReact側に持ってきたいことがたまにあるので、メモ。

やりかた

:export を使う。

colors.module.scss
$dark-087: rgba(0, 0, 0, 0.87);

:export {
    dark087: $dark-087;
}
Hoge.tsx
import style from '../style/colors.module.scss';

export default Hoge = () => (
  <div style={{
    border: `1px solid ${style.dark087}`, 
  }}>
    <p>Hello man!</p>
  </div>
);

おわり

  • 大抵は className でやるけど、必要なときに。

参考

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1