CSS Module

CSS๋ฅผ ๋ถˆ๋Ÿฌ์™€์„œ ์‚ฌ์šฉํ•  ๋•Œ ํด๋ž˜์Šค ์ด๋ฆ„์„ ๊ณ ์œ ํ•œ ๊ฐ’, ์ฆ‰ [ํŒŒ์ผ์ด๋ฆ„][ํด๋ž˜์Šค์ด๋ฆ„][ํ•ด์‹œ๊ฐ’]ํ˜•ํƒœ๋กœ ์ž๋™์œผ๋กœ ๋งŒ๋“ค์–ด์„œ ์ปดํฌ๋„ŒํŠธ ์Šคํƒ€์ผ ํด๋ž˜์Šค ์ด๋ฆ„์ด ์ค‘์ฒฉ๋˜๋Š” ํ˜„์ƒ์„ ๋ฐฉ์ง€ ํ•ด ์ฃผ๋Š” ๊ธฐ์ˆ ์ด๋‹ค.
.module.cssํ™•์žฅ์ž๋กœ ํŒŒ์ผ์„ ์ €์žฅํ•˜๋ช€ใ„ด CSS Module์ด ์ ์šฉ๋œ๋‹ค.
  • classnames CSS ํด๋ž˜์Šค๋ฅผ ์กฐ๊ฑด๋ถ€๋กœ ์„ค์ •ํ•  ๋•Œ ์œ ์šฉํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌย yarn add classnames
import classNames from "classnames"; classNames("one", "two"); // = 'one two' classNames("one", { two: true }); // = 'one two' classNames("one", { two: false }); // = 'one' classNames('one' {'two','three'}); // = 'one two three' const myClass = 'hello'; classNames('one', myClass, {myCondition:true}); // ='one hello myCondition'
import classNames from "classnames"; const MyComponent = ({ highlighted, theme }) => ( <div className={classNames("MyComponent", { highlighted }, theme)}>Hello</div> );
ย