Read state onSubmit
See original GitHub issueI expect that after action(data) the state would be updated. But it remains the previous state. How do I access the updated state?
const onSubmit = (data) => {
action(data)
console.log('data:', data) // partial store
console.log('state:', state) // previous state
}
This is invoked using RHF:
<form onSubmit={handleSubmit(onSubmit)}>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Updating state of component when onSubmit and display on ...
It works import React from "react"; import "./styles.css"; class App extends React.Component { constructor(props) { super(); this.state ...
Read more >Forms - React
In React, mutable state is typically kept in the state property of components, ... Because its value is read-only, it is an uncontrolled...
Read more >How to Get All Form Values on Submit in React - Webtips
Learn how you can properly grab all form data at once in React using a state object with useState.
Read more >Get input values on Form submit in React | bobbyhadz
To get input values on form submit in React, store the values of the input fields in state variables. Set the `onSubmit` prop...
Read more >FAQs | React Hook Form - Simple React forms validation
React Hook Form is focusing on uncontrolled inputs, which means you don't need to change the input value via state via onChange ....
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 FreeTop 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
Top GitHub Comments
Really appreciating all the examples 👍
@kevinsproles Here’s the where the
useEffect
would go in the example CSB from the docs for WizardFormFunnel: https://codesandbox.io/s/form-wizard-pages-kkg7m?file=/src/Result.js:153-204Something like:
I’ve encountered this issue as well but I believe I have figured out a work around though by simply using the Object.assign() function to the current state with the data from the current step/page/component.