useForm().setValues(...) doesn't cause input's value to update
See original GitHub issueWhat 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:
- Preferably, a CodeSandbox forked from https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple
- A link to a GitHub repo with the minimal codebase to reproduce the issue
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:
- Created a year ago
- Comments:5 (4 by maintainers)
Top 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 >
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
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.
@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>
.