0
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での入力値のリセットについて

Posted at

入力フォームのリセット

useStateを使わなくてよい。

app
export default function Form() {
  return (
    <div>
      <form>
        <input type="text" name="name" placeholder="名前1を入力してください" />
        <button type="reset">リセットする</button>
      </form>
      <form>
        <input type="text" name="name2" placeholder="名前2を入力してください" />
        <input type="text" name="name3" placeholder="名前3を入力してください" />
        <button type="reset">リセットする</button>
      </form>
    </div>
  );
}

image.png

それぞれのフォームタグごとのリセットボタンで削除される。
(下側のリセットボタンは名前2と名前3がリセットされる)

useStateに頼りがちなので備忘。

0
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
0
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?