0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Reactのファイル(.jsx)にCSSファイルをインポートする方法】

0
Posted at

CSS Modulesで書く方法

CSS Modulesは、ローカルスコープのCSSを提供する方法。
CSSファイルを作成し、コンポーネントでインポートして使用する。

<styles.module.css>

.myComponent {
  color: red;
  font-size: 18px;
}
import React from "react";
import styles from "./styles.module.css";

const MyComponent: React.FC = () => {
  return <div className={styles.myComponent}>Hello, world!</div>;
};

メリット:
スタイルがローカルスコープであるため、名前の衝突を避けられる
CSSファイルが分離されているため、可読性が高い

デメリット:
CSSファイルが増えることで、プロジェクトの構成が複雑になることがある

他にもいろんな方法があるけど今回はこの方法で使用。
他の方法はURL参照

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?