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.

useForm().setValues(...) doesn't cause input's value to update

See original GitHub issue

What you were expecting: If I wanted to programmatically set the value of an input using form.setValue(), I would expect the input to receive the value and update it’s state accordingly.

This is no longer working, and the input’s value is no longer updating.

You can view this behaviour here

There’s a setTimeout that runs after 3 seconds. The log inside of it runs, but the text doesn’t update.

What happened instead:

Steps to reproduce:

Related code:

insert short code snippets here

Other information:

Environment

  • React-admin version:
  • Last version that did not exhibit the issue (if applicable):
  • React version:
  • Browser:
  • Stack trace (in case of a JS error):

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ZachSelindhcommented, Apr 7, 2022

Try destructuring setValue from react-hook-form’s useFormContext method instead of useForm! UseForm is used to instantiate the initial form, while useFormContext is where you can pull the useForm methods from in order to use them inside the FormContext.

0reactions
slax57commented, Jun 29, 2022

@Danjavia indeed I cleaned up old sandboxes recently to make some room. But my answer is still valid. You should be able to have it work if you use the useFormContext hook inside the <SimpleForm>.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useForm - setValue
When an error is triggered or corrected by a value update. When setValue cause state update, such as dirty and touched. It's recommended...
Read more >
react-hook-form's setValue method is not working if input is ...
If I use useForm({defaultValues: {name: prop.value}}) , the default value is only set at the first time, I have to use setValue to...
Read more >
React Hook Form - useForm: setValue - YouTube
This session cover setValue API inside react hook form.Doc: https://react-hook-form.com/api/ useform / setValue.
Read more >
API Documentation
By using a custom register call, you will need to update the input value with setValue, because input is no longer registered with...
Read more >
React-Hook-Form Library | Common Use Cases
Now let's update our input fields and add a submit handler, invoking the ... import { useForm } from "react-hook-form";export default function App()...
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