Open12

React Hook FormとZodを触ってみる

よいよい

触り始めて2週間くらい経っちゃったけど
気づいたこと
理解したこと
疑問
などを書いてみる

よいよい

RHFのContorllerコンポーネント使ってるけどuseFormの返り値のcontrolの型の制御にハマっている...
フォーム全体の型になってしまうから、これじゃContorllerでラップしたコンポーネントにcontrolをpropsで渡したい時に再利用できないのでは...?

よいよい

更新フォームなど初期値をAPIから取得する場合useFormのvaluesプロパティを使う

which is useful when your form needs to be updated by external state or server data.

https://react-hook-form.com/docs/useform#values

valuesとdefaultValuesの違い

values will react to changes and reflect on the form values, and defaultValues is cached for once and will never re-run the promise or react to defaultValues changes.

https://github.com/react-hook-form/react-hook-form/releases/tag/v7.41.0

もしくはコンポーネントを分割する
https://tkdodo.eu/blog/react-query-and-forms#data-might-be-undefined

Suspenseが使えるならSuspenseを使う(dataがundefinedにならないからこれが一番良いと思う)