setSubmitting from props or redux state
See original GitHub issueQuestion?
Is it better to just not use Formik’s isSubmitting if this state is stored elsewhere (redux state).
Current Behavior
<Formik
...
onSubmit={(values) => {
sendInvite(values.email);
}}
My handleSubmit calls a redux action and I’m selecting isSubmitting via the redux state.
Desired Behavior
<Formik
...
submitting={submitting}
formikWillReceiveProps={(props, nextProps, {setSubmitting}) => {
if (props.submitting && !nextProps.submitting) {
setSubmitting(false);
}
}}/>
Additional Information
Is this https://github.com/jaredpalmer/formik/issues/401?
- Formik Version: 0.11.11
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:14 (3 by maintainers)
Top Results From Across the Web
setSubmitting from props or redux state · Issue #502 - GitHub
My handleSubmit calls a redux action and I'm selecting isSubmitting via the redux state. Desired Behavior. <Formik ... submitting={submitting} ...
Read more >How to run setSubmitting() outside the submit handler?
Another approach is by using ref on to the <Formik/> component (released in React 16.3) class NewComponent extends Component { formikRef ...
Read more >Integrating Formik and Redux: complex forms made easy
The trick is in the built-in props we mentioned before; they are really handy when validating fields and managing forms states. Many props ......
Read more >Building forms with Formik in React - LogRocket Blog
Building forms with React involves setting up state as the container for user data and props as the means to control how state...
Read more >Connect: Extracting Data with mapStateToProps - React Redux
The first argument to a mapStateToProps function is the entire Redux store state (the same value returned by a call to store.getState() )....
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
I’ve just started using Formik on a project with redux-saga and so far I’m ignoring the
isSubmitting
prop and using the request status from my redux store to control things like the spinner. Are there any caveats I should be aware of by ignoring the built inisSubmitting
?I agree that there should be a single source of truth for this piece of state, but in a redux app I don’t think that’s the responsibility of the UI code. Is there a recommended way for using externally supplied state to drive the Formik
isSubmitting
state?Thanks, I’ve resolved this. I usually call redux actions and not api services directly, but thankfully redux-thunk allows these actions to return a promise that I can use for toggling setSubmitting.