redux-form: Manually update store then trigger form submission synchronously

It would be great if there was a way to add/update a value manually on the form, then submit the form right after. For instance, in a form that tokenizes a credit card token for Stripe, I’d like to handle the Stripe response by setting the token ID in the callback then triggering form submit. Something like this:

stripeResponseHandler = (status, response, values) => {
    if(response.error) {
      // Stuff
      this.setState({
        error: response.error.message
      })
    } else { // Token created
      this.clearError()
      // These next two lines would need to happen syncronously, the submit would need to wait for the change.
      this.props.change('customer.stripe_token', response.id)
      this.onSubmit() // Whatever function I'd normally pass to the form's handleSubmit prop
    }
  }

This is pretty standard in regular forms, and it may very well be possible with redux-form, but I’ve looked through similar issues and don’t see anything that would work.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

Didn’t know about this: "setState() does not immediately mutate this.state but creates a pending state transition. … "

That’s why they’re appending the json directly.

http://stackoverflow.com/a/36070293/981177 <-- still not convinced change is synchronous…

But yes your method could work as well!