๐Ÿฅ TIP

[ERROR] Warning: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.

Eun_zii 2023. 10. 30. 15:54

 

form ํ•„๋“œ์— value๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ onChange ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š์•„ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ

 

โœ… ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

 

1. onChange ํ•ธ๋“ค๋Ÿฌ ์„ค์ •

const onChange = () => {
    // onChange ์ด๋ฒคํŠธ 
}

<input
  value={value}
  onChange={onChange}
/>

 

2. defaultValue ์˜ต์…˜ ์„ค์ •

: value ์˜ต์…˜์„ defaultValue๋กœ ๋ณ€๊ฒฝ

<input
  defaultValue={value}
/>

 

3. readonly ์˜ต์…˜์ถ”๊ฐ€

<input
  value={value}
  readonly
 />
728x90