๐จ ์๋ฌ๋ฐ์
js๋ก ๋ง๋ ํ์ผ์ react๋ก ์ฎ๊ธฐ๋๋ฐ ๊ฐ์ ํด๋์ค์ด๋ฆ์ ๊ฐ์ง css์คํ์ผ์ด ๊ฐ์ด ์ ์ฉ๋๋ ๋ฌธ์ ๋ฐ์..!
๐ซง ์ฌ์ฉ์ด์ ?
ํด๋์ค๋ช (className)์ด ์ถฉ๋ํ๋ ๊ฒ์ ๋ฐฉ์งํด์ค๋ค.
์ ์ง๋ณด์ํ๊ธฐ ํธํด์ง๋ค.
๊ฐ๊ฒฐํ ํด๋์ค๋ช ์ ์ด์ฉํด ์ปดํฌ๋ํธ ๋จ์๋ก ์คํ์ผ์ ์ ์ฉํ ๋ ์ ์ฉํ๋ค.
react์์ ๋ชจ๋์ ์ฌ์ฉํ์ง ์์ ์, ๋ถ๋ชจ ์ปดํฌ๋ํธ์ css๊ฐ ์๋ ๋ค์๊ฒ ๋ชจ๋ ์ ์ฉ๋์ด side effect ๋ฐ์ ํ๋ฅ ์ด ๋์์ง๋ค!
๊ธฐ์กด ํ๋ก์ ํธ์ css ํด๋์ค์ ์ด๋ฆ์ด ์ค๋ณต๋์ด๋ ์คํ์ผ์ด ๊ผฌ์ด์ง ์๋๋ก cssํ์ผ์ ํ์ฅ์๋ฅผ .module.css๋ก ๋ง๋ ๋ค.
๐ ๋ค๋ฅธ ํ์ผ์ด ๊ฐ์ ํด๋์ค๋ช
์ ์ฌ์ฉํด๋ ์ค์ฒฉ๋์ง ์๋๋ค.
import React from "react";
import styles from "./Box.module.css";
const CSSModule = () => {
return (
<div className={styles.Box}>
Box
</div>
);
};
export default Box;
---------------------------------------------
<button className={`${style.buttonColor} ${style.fontColor}`}>๋ฒํผ</button>
//์ฌ๋ฌ๊ฐ์ ํด๋์ค ์ ์ฉ ์ ๋ฐฑํฑ ์ฌ์ฉ
๐ .module.css ํ์ฅ์๋ก ํ์ผ์ ์ ์ฅ
๐ import styles from "CSS module ํด๋์ค๋ช
"