colinbate / redux-form-submit-saga

Handles redux-form submissions using redux-saga
MIT License
61 stars 12 forks source link

Consider putting an example of form to avoid stupid people like me opening issues #5

Closed danielo515 closed 7 years ago

danielo515 commented 7 years ago

Hello,

I know is kind of weird that I open an issue to prevent people like me opening issues of this kind... but life is sometimes this strange.

My problem was about the onSubmit handler. I was making sure to put the correct onSubmit function on the reduxForm factory:

export default reduxForm({
    form: formConfig.formName,  // a unique identifier for this form
    onSubmit: onSubmitActions(LOGIN),
    initialValues: fromJS({username:'', password:''})
})(LoginForm)

But I was calling the handleSubmit on my form instead of just passing in the handle, so I was doing <Form horizontal onSubmit={handleSubmit()}> instead of <Form horizontal onSubmit={handleSubmit}>. Probably a stupid error that is totally my fault, but I think it is good to make it noticeable.

Probably what confused me was the following sentence:

This is assuming you are using handleSubmit within your form and not passing it anything.

I supposed that you should call handleSubmit without parameters, but you don't have to call it at all.

Regards

TrevorHinesley commented 7 years ago

The problem with your original implementation is not that you don't have to call it, but that you're calling it on render by including the parentheses. By removing the parentheses, you're essentially giving onSubmit a reference to the function to call it, rather than giving it the result of the already-executed-on-render handleSubmit().

danielo515 commented 7 years ago

Dear @TrevorHinesley, you are totally right. I don't know what I was thinking when I wrote that piece of code. Probably I was confused about reading the documentation too late at night. However I still think that a simple example will help much more than the best of the explanations.

Regards

colinbate commented 7 years ago

Hi @danielo515 Sorry for the confusion and the delay. I just updated the README to include the form definition and tweaked the wording. Hopefully this is more clear.

danielo515 commented 7 years ago

Dear @colinbate I can't see the difference. May you point me to the commit so I can better check it?

colinbate commented 7 years ago

In case you hadn't found it, the commit was: https://github.com/colinbate/redux-form-submit-saga/commit/523ae8613cd9cd1e20e65cc4ccb0de2a21c6cf69

danielo515 commented 7 years ago

Much better now. Thanks a lot