React Hook Form のサンプル集

これらのサンプルは、公式リポジトリの examples ディレクトリにあります。

置き場所を知らない人も多そうなので、ここで紹介します。

例の名前

リンク

送信時の非同期バリデーション

https://codesandbox.io/s/react-hook-form-async-submit-validation-hy9oe

フォームの値を非同期で設定

https://codesandbox.io/s/react-hook-from-async-set-form-values-tyk12

フィールドの非同期バリデーション

https://codesandbox.io/s/react-hook-form-async-field-validation-w1chw

フィールド配列のネスト

https://codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-m8w6j

基本

https://codesandbox.io/s/react-hook-form-basic-6mlii

基本的なバリデーション

https://codesandbox.io/s/react-hook-form-basic-validation-qdyye

カスタムバリデーション

https://codesandbox.io/s/react-hook-form-custom-validation-8kuu7

条件付きフィールド

https://codesandbox.io/s/react-hook-form-conditional-fields-qgr41

カスタム入力

https://codesandbox.io/s/react-hook-form-custom-input-hmyeu

Controller と MUI や React Select の連携

https://codesandbox.io/s/react-hook-form-v7-controller-5h1q5

Controller の戻り値を変換

https://codesandbox.io/s/react-hook-form-v7-customise-controller-return-value-wuhrd

チェックボックスの最小選択数(ネイティブ)

https://codesandbox.io/s/checkbox-min-checked-forked-0tkjz

フィールドの値を比較

https://codesandbox.io/s/react-hook-form-getvalues-compare-field-values-orf0p

フィールドのデフォルト値

https://codesandbox.io/s/react-hook-form-defaultvalues-wv8c4

フォームのデフォルト値と初期値

https://codesandbox.io/s/react-hook-form-defaultinitial-form-value-cujvt

変更済み、操作済み、送信済みの状態

https://codesandbox.io/s/react-hook-form-formstate-dirty-touched-submitted-forked-wjk0k

変更したフィールドだけを送信

https://codesandbox.io/s/react-hook-form-submit-only-dirty-fields-ol5d2

ネイティブのバリデーションを無効化

https://codesandbox.io/s/purple-glitter-4pgqq

フィールド配列の最小要素数

https://codesandbox.io/s/react-hook-form-fieldsarray-yup-validation-min-length-k87iy

制御コンポーネントを使ったフィールド配列

https://codesandbox.io/s/infallible-bush-c92l0

条件付きフィールド配列

https://codesandbox.io/s/react-hook-form-conditional-0g9qx

FormProvider によるフォームの共有

https://codesandbox.io/s/react-hook-form-form-context-2703c

入力値の解析と整形

https://codesandbox.io/s/react-hook-form-parse-and-format-textarea-zbgog

モーダルで入力欄の表示を切り替え

https://codesandbox.io/s/react-hook-form-modal-form-conditional-inputs-h09tf

ネストしたフィールド

https://codesandbox.io/s/react-hook-form-nested-fields-9xhg0

ネストしたフォーム

https://codesandbox.io/s/react-hook-form-nested-portal-bw8m75

フィールドの値を正規化、整形、マスク

https://codesandbox.io/s/react-hook-form-normalize-field-forked-jhrq9

フォームをリセット

https://codesandbox.io/s/react-hook-form-reset-form-r8z56

フォームの外から送信を実行

https://codesandbox.io/s/remote-handlesubmit-ipbqb

入力欄とエラーメッセージの登録

https://codesandbox.io/s/react-hook-form-register-with-error-messages-h9m8p

入力欄や選択欄の値を設定

https://codesandbox.io/s/react-hook-form-set-inputselect-value-forked-kh0mk

入力欄や選択欄にエラーを設定

https://codesandbox.io/s/react-hook-form-set-error-clear-error-rmtp1

タブ付きフォーム(MUI)

https://codesandbox.io/s/tab-form-34oio

フィールドのバリデーションを実行

https://codesandbox.io/s/react-hook-form-trigger-validation-utih0

バリデーション用スキーマ

https://codesandbox.io/s/react-hook-form-validationschema-v6-12p66

フォーカスが外れたときや値が変わったときに検証

https://codesandbox.io/s/react-hook-form-validation-onblur-onchange-pnq16

ウィザード形式の複数ステップフォーム

https://codesandbox.io/s/react-hook-form-wizard-form-ir780

React Native

型・API 名

リンク

React Native での Controller

https://snack.expo.io/@bluebill1049/react-hook-form-v7---controller

型

このライブラリで使える型のサンプルです。