What to consider in integrating react-hook-form with zustand. #1922
-
When I embarked on the development of my app, I initially prioritized simplicity over architectural design. However, as my app grew more complex and I aimed to implement validation using the powerful react-hook-form library, I found myself grappling with the challenge of integrating it seamlessly. Given that react-hook-forms already handles form data for me, and all my form data currently relies on zustand, I'm in need of guidance on the best approach to integrate the two. At present, I utilize a slice similar to the following code snippet to manage form data: export const createDataFormSlice = (set) => ({
dataForm: {},
updatePrimitive: (key, value) => set(state => ({
dataForm: {
...state.dataForm,
[key]: value
}
})),
resetDataForm: () => set({ dataForm: {} })
}) For each input field, I attach an event listener like onChange, which updates the dataForm accordingly. I am beginning to question whether my usage of zustand has been flawed all along, perhaps due to my limited knowledge and hasty decision-making. I would be immensely grateful for any guidance, suggestions, or insights you can offer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I think this question is pointless |
Beta Was this translation helpful? Give feedback.
@ahmadxgani I would leave
RHF
as is. Having to sync that data with zustand and viceversa is not a good idea.