Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v5] - Pass parent props into custom handleSubmit() #1546

Closed
baronswindle opened this issue Aug 16, 2016 · 4 comments
Closed

[v5] - Pass parent props into custom handleSubmit() #1546

baronswindle opened this issue Aug 16, 2016 · 4 comments

Comments

@baronswindle
Copy link
Contributor

I'd really like to be able to do something like this:

function handleSubmit(values, dispatch, props) {
  return () => {
    const { policyType } = props;
    return createUserWithPolicy({
      policyType,
      user: { ...values }
    })
      .catch(error => Promise.reject({ _error: error.message }));
  };
}

I reckon it's possible to do this by making policyType a form field and managing its value at the level where it would change using redux-form field properties, but it would be worlds easier to just pass parent props into the handleSubmit() function. It'd be pretty easy to do; I've already made the change on my personal fork that I'm using in a project. So if nobody has any objections, I'd happily make the PR.

Let me know what you guys think.

@naw
Copy link
Contributor

naw commented Aug 16, 2016

Have you considered generating your handleSubmit function with a factory that receives policyType?

function handleSubmitFactory(policyType) {
  return (values) => {
    // createUser...
  }
}

<form onSubmit={handleSubmitFromReduxForm(handleSubmitFactory(props.policyType))}>

@baronswindle
Copy link
Contributor Author

@naw There definitely are other ways to do it, and your suggestion seems like a fine one. Still, I think this could be an improvement to redux-form and make the API more consistent. For example, validate() and asyncValidate() functions receive the component's props as an argument, so it seems reasonable that the handleSubmit() function should as well.

@erikras
Copy link
Member

erikras commented Aug 25, 2016

Released @baronswindle's fix in v5.3.3.

@lock
Copy link

lock bot commented Jun 2, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants