Update Form defaultValues after Redux inject using reset api
See original GitHub issueHi there,
I want to use defaultValues coming from Redux within my Form. Although when I directly visit the url from my browser and there is no customer yet, the Form isn’t filled correctly. So this screenshot shows the lifecycle:
At first the customer is undefined. The docs say that I should run the reset API when the defaultValues change to simulate the correct behaviour. This is my code:
const dispatch = useDispatch();
const customer = useSelector(customerSelector);
const formMethods = useForm<i.Customer>({
mode: 'onChange',
defaultValues: mapCustomer(customer),
});
const { register, handleSubmit, reset } = formMethods;
React.useEffect(() => {
if (customer) {
reset(mapCustomer(customer));
}
}, [customer]);
Although unfortunately nothing happens. How can I insert my Redux data in my Form correctly?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How to change React-Hook-Form defaultValue with useEffect()?
After you call API and get back response data, you call reset with new apiData, make sure apiData key's are same as input...
Read more >React Hook Form - Reset form with default values and clear ...
This is a quick example of how to reset a React Hook Form with default values and clear form validation error messages.
Read more >useForm - reset - React Hook Form
An optional object to reset form values, and it's recommended to provide the entire defaultValues when supplied. keepErrors, boolean. All errors will remain....
Read more >Initializing From State - Redux Form
By default, you may only initialize a form component once via initialValues . There are two methods to reinitialize the form component with...
Read more >Initializing State | Redux
Note: Reducers whose initial state is populated using preloadedState will still need to provide a default value to handle when passed a state...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@bluebill1049 Unfortunately I’m still not able to get the issue resolved. Gonna try tomorrow in production mode
no worries @rnnyrk let me know if anything else i can help. i try my best.