πŸ“ μŠ€νƒ€μΌλ“œ μ»΄ν¬λ„ŒνŠΈλ‘œ props λ„˜κ²¨μ€„λ•Œ, Dom μš”μ†Œλ‘œ μ „λ‹¬λ˜λŠ” 문제( 포인티 λ””μžμΈ μ‹œμŠ€ν…œ ν”„λ‘œμ νŠΈ )

10_2pangΒ·2023λ…„ 7μ›” 31일
1

βš½οΈνŠΈλŸ¬λΈ”μŠˆνŒ…

λͺ©λ‘ 보기
81/94
post-thumbnail

πŸ‘¨β€πŸ’»Β μ‚¬κ±΄


μŠ€νƒ€μΌλ“œ μ»΄ν¬λ„ŒνŠΈλ₯Ό μƒμ„±ν•˜κ³ , ν•΄λ‹Ή νƒœκ·Έμ— props λ₯Ό λ‚΄λ €λ°›μ•„ 속성에 ν•΄λ‹Ήν•˜λŠ” μŠ€νƒ€μΌμ„ μ²˜λ¦¬ν•΄μ£ΌκΈ°μœ„ν•΄ μ‚¬μš©ν–ˆλ‹€.

...
<St.ButtonWrapper size={size} state={state} disabled={isDisabled}>
...
export const ButtonWrapper = styled.button<{ size: ButtonSize; state: ButtonState }>`
  display: flex;
  justify-content: center;
	...

λ Œλ”ν•˜λŠ”κ²ƒμ—λŠ” λ¬Έμ œκ°€ μ—†μ§€λ§Œ, ν•΄λ‹Ή button νƒœκ·Έμ— ν•„μš”μ—†λŠ” 속성듀이 λΆ™μ—ˆκ³ , μ•„λ‹ˆλ‚˜ λ‹€λ₯ΌκΉŒ warning 문ꡬ가 λ°œμƒν•˜μ˜€λ‹€.

styled-components: it looks like an unknown prop "state" 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 `<StyleSheetManager shouldForwardProp={...}>` (connect an API like `@emotion/is-prop-valid`) or consider using transient props (`$` prefix for automatic filtering.)

βœ…Β ν•΄κ²°


μ—¬λŸ¬κ°€μ§€ 방법이 μžˆμ§€λ§Œ, λ‚΄κ°€ μ„ νƒν•œ 방법은 transient propsλ₯Ό μ‚¬μš©ν•˜λŠ”κ²ƒμ„ νƒν•˜μ˜€λ‹€.
$ 접두사λ₯Ό μ‚¬μš©ν•˜μ—¬ transient propsλ₯Ό λ§Œλ“€λ©΄, 이 propsλŠ” styled component의 μŠ€νƒ€μΌλ§μ„ μœ„ν•΄ μ‚¬μš©λ˜μ§€λ§Œ μ‹€μ œ DOM μš”μ†Œλ‘œ μ „λ‹¬λ˜μ§€ μ•Šμ•„ μ›ν•˜λŠ” λ°©ν–₯이닀.

...
<St.ButtonWrapper $size={size} $state={state} disabled={isDisabled}>
  ...
</St.ButtonWrapper>
...
export const ButtonWrapper = styled.button<{ $size: ButtonSize; $state: ButtonState }>`
  display: flex;
  justify-content: center;
	...

πŸ’­Β κ°œμ„ 


  • λ¬΄μ—‡λ•Œλ¬ΈμΈμ§€λŠ” λͺ¨λ₯΄κ² μœΌλ‚˜, ν˜„μž¬ λ§Œλ“€κ³ μžˆλŠ” λ²„νŠΌμ„ app μ—μ„œ ν…ŒμŠ€νŠΈ 해보렀고 import ν•˜μ—¬ μ‚¬μš©ν–ˆμ„λ•Œ, props λ₯Ό μ μ§€μ•Šμ•„λ„ νƒ€μž… 였λ₯˜κ°€ λ°œμƒν•˜μ§€ μ•ŠλŠ” μ—λŸ¬κ°€ λ°œμƒν•˜μ˜€λ‹€. 이λ₯Ό μ²˜λ¦¬ν•˜κ³ μž μ—¬λŸ¬ λ°©μ•ˆμ„ ν…ŒμŠ€νŠΈ 해보도둝 ν•΄μ•Όκ² λ‹€.
profile
μ£Όλ‹ˆμ–΄ ν”„λ‘ νŠΈμ—”λ“œ 개발자 이광렬 μž…λ‹ˆλ‹€ 🌸

0개의 λŒ“κΈ€