LoginSignup
3
1

react-hook-formのデータ(data)の型定義

Last updated at Posted at 2024-03-06

はじめに

どうもこんにちは!僕は現在1ヵ月本気の技術力向上を目指している現役高校1年生、@shuniiです!
今回はreact-hook-formで戸惑ったことを共有します。

問題

react-hook-formで作ったフォームの送信ボタンを押したときに返却されるデータの方を指定できない。

解決方法

useFormに定義する

以下はサンプルになります。

type FormValues = {
    id: string;
    name: string;
};

export const SamplePage = () => {
  const {
    register,
    handleSubmit,
    formState: { errors },
    reset,
  } = useForm<FormValues>(); //  <=  ここ
}

終わりに

useStateと同じ定義の仕方でした~

About Me

  • X(Twitter)

参考

公式ドキュメント最強💪

3
1
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
3
1