Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validation in reducer in redux

this question is about where to put validation of an form element in redux. I feeeeel as though I should have an onValueChange event that dispatches an action to the reducer that validates and updates both the value ( invalid or valid as it may be ) as well as the "isValid" property on state so that that element can then display an error.

Conversely, I could do the validation in the action, and if it fails just dispatch a failure action instead.

One note is that i do prefer the anonymous function nomenclature to extending the react.component.

I guess I should change then name of this to where is the proper place to put validation in the redux flow.

like image 624
Raif Avatar asked Mar 13 '16 16:03

Raif


1 Answers

Keep the validation in your component. I hear a lot of "keep all state in redux", but I try to only keep what I absolutely need in redux. Use component state with a error property and if your validation fails set the state on the error property. As well, redux forms: http://redux-form.com/4.2.0/#/?_k=mhjui4 is a good library for simple and complex forms.

like image 119
groovy Avatar answered Nov 10 '22 10:11

groovy