New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
examples(RHF): support for default{Value,Checked} & useFieldArray #134
Conversation
4bb5e51
to
fc640ff
Compare
fc640ff
to
12b2310
Compare
ea37744
to
4daabb9
Compare
4daabb9
to
0a1dd78
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked a few questions, but LGTM.
Thanks!
}, [setFormValues, getValues]) | ||
|
||
const useFieldArraySync = ( | ||
props: UseFieldArrayProps<TFieldValues> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo: RHFのuseFieldArray
はimportして使うと思うので、↓みたくしてimprot { useFieldArraySync }
して使うというのは微妙ですかね?
その方がhooksっぽいかなって気もしたものの、自信ないのでご意見いただきたいです🙇♂️
const { ... } = useFieldArraySync({
onChangeForm,
props,
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最初はまさにそのつもりだったのですが、将来onChangeForm()
以外を渡さないといけなくなる可能性を考えると最初からクロージャにしちゃった方がいいだろうと思いました
別案としてはuseFormSync()
からラップしたcontrol
を返してそれをuseFieldArraySync()
に渡すというのも考えたのですが、ラップするオブジェクトが増え続けるのもどうかかと思いクロージャ案を選びました
useFormSync()
するコンポーネントとuseFieldArraySync()
するコンポーネントが分かれる場合はcontrol
をラップするのが一番使い勝手がいい気はします
他の2案ではcontrol
に加えてuseFieldArraySync
かonChangeForm
のどちらかも一緒に子コンポーネントに渡さないといけないので
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これの結論が出るまでマージ保留にします
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
将来onChangeForm()以外を渡さないといけなくなる可能性を考えると最初からクロージャにしちゃった方がいいだろうと思いました
確かにですね...
方針納得しました!
useFormSync()するコンポーネントとuseFieldArraySync() するコンポーネントが分かれる場合はcontrolをラップするのが一番使い勝手がいい気はします
一応知っておきたいんですが、ラップするというのは↓みたいなイメージであってますか?
const { control } = useFormSync(...)
// controlはRHFのcontrol + onChangeForm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そのイメージです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
方針納得しました!
とのことなのでこれでマージします!
Support for
defaultValue
Use
registerWithDefaultValue
instead ofregister
:Even SSR/SSG, it is rendered with default values.
Support for
defaultChecked
Use
registerWithDefaultChecked
instead ofregister
Support for useFieldArray
Use
useFieldArraySync
returns fromuseFormSync
instead ofuseFieldArray
:Of course, it is possible to use
registerWithDefaultValue
instead ofregister
.