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.

setSubmitting from props or redux state

See original GitHub issue

Question?

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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

35reactions
dabrownecommented, Jul 24, 2018

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 in isSubmitting?

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?

12reactions
deanbotcommented, Mar 10, 2018

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.

Read more comments on GitHub >

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

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