Home [Error] You provided a value prop to a form field without an onChange handler
Post
Cancel

[Error] You provided a value prop to a form field without an onChange handler


Warning: You provided a value prop to a form field without an onChange handler. 발생

해결

기존 코드
1
2
3
4
5
6
7
8
9
10
11
12
13
import React, { useEffect, useState } from "react";

const Info = () => {
  const [id, setId] = useState<string>("");

  return (
    <div>
      <input value={id} placeholder="아이디를 입력해주세요" />
    </div>
  );
};

export default Info;
수정 코드
1
2
3
4
5
6
7
8
9
10
11
12
13
import React, { useEffect, useState } from "react";

const Info = () => {
  const [id, setId] = useState<string>("");

  return (
    <div>
      <input defaultValue={id} placeholder="아이디를 입력해주세요" />
    </div>
  );
};

export default Info;

마치며

혹시 잘못된 정보나 궁금하신 게 있다면 편하게 댓글 달아주세요.
지적이나 피드백은 언제나 환영입니다.

This post is licensed under CC BY 4.0 by the author.