
const Container = styled.div<{ $bgcolor?: string }>`
background-color: ${(props) =>
props.$bgcolor === bgBright
? "#f6e8cf"
: props.$bgcolor === bgCloudy
? "#dbe1da"
: "#233947"};
`;
// API ๋ฐ์ดํฐ ๋ฐ์์ props๋ก ์ ๋ฌ
<Container $bgcolor={weather[0].icon}>
์ผํญ์ฐ์ฐ์ ๋ด๋ถ์ ์ผํญ์ฐ์ฐ์๋ฅผ ์ฐ๋ฌ์ ์ฌ์ฉํ๋ ๊ฑด ๊ฐ๋ ์ฑ์ ์ ํํ ์ ์์ด์ ๊ทธ๋ค์ง ๋ง์ด ์ฐ๋ ๋ฐฉ๋ฒ์ ์๋์ง๋ง, styled-component์์ ์กฐ๊ฑด๋ถ๋ก CSS๋ฅผ ์ ์ฉํ๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
๋ฐฐ๊ฒฝ์์ ๋ฐ์์จ API ๊ฒฐ๊ณผ์ ๋ฐ๋ผ ๋ค๋ฅด๊ฒ ์ ์ฉํ๊ธฐ ์ํด ์ฌ์ฉํ๋๋ฐ ๋ถ๊ธฐ์ ์ด 2๊ฐ์๊ธฐ ๋๋ฌธ์ ํฌ๊ฒ ๊ฐ๋ ์ฑ์ ํด์น์ง ์๋ ์ ์์ ํ์ฉํ ์ ์์๋ค.
Warning: React does not recognize the bgColor prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase bgColor instead. If you accidentally passed it from a parent component, remove it from the DOM element.
Attribute์ bgColor๋ก ์ด๋ฆ์ ์ค์ ํ๊ณ ๊ฐ์ ๋๊ฒผ๋๋ React์์ prop์ผ๋ก ์ธ์ํ ์ ์๋ค๋ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค. DOM์ Custom Attribute๋ก ์๋์ ์ผ๋ก ๋ง๋ ๊ฒฝ์ฐ๋ผ๋ฉด ๋ชจ๋ ์๋ฌธ์๋ก ๋ณ๊ฒฝํ๋ผ๊ณ ์๋ ค์ค์ ์ด ๋ถ๋ถ์ ์์ ํ๋๋ ํด๋น ์๋ฌ๋ ๋ฐ์ํ์ง ์์๊ณ ์กฐ๊ฑด๋ถ๋ก ์ค์ ํ CSS๋ ์ ์ ์ฉ๋๋ ๊ฒ์ฒ๋ผ ๋ณด์๋ค(ํ์ง๋ง ๊ทธ๊ฑด ์ฐฉ๊ฐ์ด์๋ค).
styled-components: it looks like an unknown prop "bgcolor" is being sent through to the DOM, which will likely trigger a React console error.
If you would like automatic filtering of unknown props, you can opt-into that behavior via
(connect an API like @emotion/is-prop-valid )
or consider sing transient props ($prefix for automatic filtering.)
styled-component์์ ์ฐ๊ธฐ ์ํด ์์์ ๋ง๋ custom attribute๊ฐ React ์ฝ์์์ ์๋ฌ๋ฅผ ๋ฐ์์์ผฐ๋ค. ์ฆ, ์กฐ๊ฑด๋ถ CSS๊ฐ ์๋์ ํ์ง๋ง ์๋์ผ๋ก ํํฐ๋ง์ด ๋๋ ๊ฒ ๊ฐ์๋ค. ์น์ ํ๊ฒ๋ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์ด์ ์ ์ผ ๋์ ์จ์์๊ณ , ๋ค๋ฅธ ๋ธ๋ก๊ทธ๋ฅผ ์ฐธ๊ณ ํด์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค.
// ๊ธฐ์กด ์ฝ๋
const Container = styled.div<{ $bgcolor?: string }>`
background-color: ${(props) =>
props.bgcolor === bgBright
? "#f6e8cf"
: props.bgcolor === bgCloudy
? "#dbe1da"
: "#233947"};
`;
<Container bgcolor={weather[0].icon}>
// ์์ ์ฝ๋
const Container = styled.div<{ $bgcolor?: string }>`
background-color: ${(props) =>
props.$bgcolor === bgBright
? "#f6e8cf"
: props.$bgcolor === bgCloudy
? "#dbe1da"
: "#233947"};
`;
<Container $bgcolor={weather[0].icon}>