extended-salmon
extended-salmon16mo ago

Hello everyone I just want to understand

Hello everyone.. I just want to understand something but IDK if this is the right channel or should I use discussions.. if not right channel let me know.. In react-hook-form in useForm function, why don't you directly declare defaultValues  in the useHookForm in this line, rather use useEffect to go over the fields and set the values? (in line #L130. Since defaultValues can be undefined, just setting queryResult?.data?.data solves the problem. If I set it that way, I can use useFieldArray properly in my code, now I have to jump some hoops to clearly reflect the fields. Is there a specific reason not to use that, maybe I am missing something?
2 Replies
kapa.ai
kapa.ai16mo ago
Hi @kingofsevens. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: Sorry @kingofsevens, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist: Perhaps try again in 15mins?
unwilling-turquoise
unwilling-turquoise16mo ago
Okay, now my solution is not working either. However, below seems to work better..
useEffect(() => {
if (typeof queryResult?.data !== "undefined") {
reset(queryResult?.data?.data || {} as any)
}
}, [queryResult?.data, reset])
useEffect(() => {
if (typeof queryResult?.data !== "undefined") {
reset(queryResult?.data?.data || {} as any)
}
}, [queryResult?.data, reset])