1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【React】Uncaught Error: Objects are not valid as a React child

Last updated at Posted at 2025-04-15

はじめに

Reactでイベントに関数をセットする際に発生したエラーについてまとめました

問題

以下、inputタグの onChange イベントにstateのセットを設定しようとすると Uncaught Error: Objects are not valid as a React childというエラーが出ました。

  const [studyContent, setStudyContent] = useState("");
  const changeContent = (value) => {
    setStudyContent(value);
  };
  return (
      <>
          <input value={studyContent} onChange={changeContent} />
          ...
      </>
  );

入力ホームに入力するとタイトルのエラーが出て、画面が真っ白になる

解決方法

ラムダ式で記述し、e.target.value を受け取るようにする。

<input value={studyContent} onChange={(e) => changeContent(e.target.value)}/>

おわりに

イベント時に発生する value の変更は e.target.value で受け取ること

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?