question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update Form defaultValues after Redux inject using reset api

See original GitHub issue

Hi 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:

Screenshot 2020-03-10 at 14 35 57

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rnnyrkcommented, Mar 12, 2020

@bluebill1049 Unfortunately I’m still not able to get the issue resolved. Gonna try tomorrow in production mode

0reactions
bluebill1049commented, Mar 16, 2020

no worries @rnnyrk let me know if anything else i can help. i try my best.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found