styled components attrs - boostcamp-2020/Project15-B-Client-Based-Formula-Editor GitHub Wiki
styled-components attrs
styled-components์ attrs ์์ฑ์ ์ ์ ์ธ ์์ฑ, ์๋ฅผ๋ค๋ฉด input์ type์ด๋ radio ๋ฒํผ์ checked์ ๊ฐ์ ๊ฒ๋ค์ ์ค์ ํ ์ ์์ผ๋ฉฐ, ๋์ ์ผ๋ก ๋ณํํ๋ ์์ฑ์ ๋ํด์๋ ์ฌ์ฉํ์ฌ ์ต์ ํ ํ ์ ์์ต๋๋ค. ์ ๊ฐ ๊ฒช์๋ ์ด์๋ attrs๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ํ
ํ๋ฆฟ ๋ฆฌํฐ๋ด ๋ด๋ถ์ "${}"๋ฅผ ์ฌ์ฉํ์ฌ onChange์ ๋ฐ๋ผ ์๋ณ๊ฒฝ์ ํด์ฃผ์์๋๋ฐ, ์ด๋ ๊ฒ ํ๊ฒ๋๋ ๋ ์ด ๊ฑธ๋ฆฌ๊ณ Over 200 classes were generated for component styled.div. Consider using the "attrs" method, together with a style object for frequently changed styles.
์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ด ์ํฉ์์ attrs๋ฅผ ์ฌ์ฉํ๋ฉด ์ต์ ํ๋ฅผ ํด์ฃผ๋ ๊ฒ ๊ฐ์ต๋๋ค.
// ๊ธฐ์กด ์ฝ๋
const Layout = styled.div`
font-size: 16px;
color: ${props => props.color};
`;
// attrs๋ฅผ ์ฌ์ฉํ ์ฝ๋
const Layout = styled.div.attrs(props => ({
color: props.color,
}))`
font-size: 16px;
`;