์คํ์ผ ์ปดํฌ๋ํธ & ํ์
์คํฌ๋ฆฝํธ๋ก ํ๋ก์ ํธ๋ฅผ ์งํํ๋ ๋์ค์
ํด๋น ์คํฌ๋กค ์์น ์กฐ๊ฑด์ ๋ฌ์ฑํ ๊ฒฝ์ฐ์, ์ปดํฌ๋ํธ๋ฅผ ๊ณ ์ ์ํค๊ณ ์ถ์๋ค.
ํ์ง๋ง ์ผ๋ฐ ๋ฆฌ์กํธ๋ก ์งํํ๋ ๊ฒ์ฒ๋ผ props๋ก ๋จ์ ์กฐ๊ฑด๋ฌธ์ ์ํด์ props๋ฅผ ์ ๋ฌํด์ฃผ์๋๋ CSS ์์ฑ์ด ์ ๋๋ก ์ ํ์ง์ง ์์๋ค.
์ปดํฌ๋ํธ ์์ฑ์ ํ๊ทธ ์ฐ์ธก์ props ํ์
์ ์ ์ํด์ผ ํ๋ค.
fixBar์ ๊ฐ์ useState๋ก ์คํฌ๋กค ๊ฐ์ง์ Y์ถ์ ๊ฐ์ ๋ฐํํ๋ค.
const Box = styled.div<{inverted:boolean}>` // ์ฌ๊ธฐ!
position: ${(props)=> (props.inverted ? 'fixed':'absolute')};
left: ${(props)=> (props.inverted ? '87%':'87%')};
top : ${(props)=> (props.inverted ? '60%':'1200px')};
`
//...//
<Box inverted = { fixBar < 700 ? true : false }>