Firstly, here is an example that I will talk about below: http://jsbin.com/rixido/2/edit
How to validate input values โโusing React.JS?
However you want to. The reagent is designed to render a data model. The data model must know what is valid or not. You can use Backbone models, JSON data, or whatever you want to represent data, and this is an error condition.
More specific:
The reaction is usually independent of your data. This is for rendering and event handling.
Following are the following rules:
- Items
- can change their state.
- they cannot change the details.
- they can call a callback that will change the top-level details.
How to decide whether something should be a pillar or a state? Consider this: ANY part of your application, besides a text field, wants to know that the value entered is bad? If not, make this condition. If so, then this should be support.
For example, if you need a separate view for rendering "You have 2 errors on this page." then your error should be known to the top-level data model.
Where should this error be?
If your application displayed Backbone models (for example), the model itself would have a validate () method and a validateError property that you could use. You could display other intelligent objects that could do the same. The reaction also suggests trying to keep the details to a minimum and generate the rest of the data. therefore, if you have a validator (e.g. https://github.com/flatiron/revalidator ), your checks can leak down and any component can check the details with the appropriate check to make sure it is valid.
It is largely up to you.
(I personally use Backbone models and render them in React. I have a warning error message that I show if there is an error somewhere describing the error.)
z5h Jun 12 '14 at 20:12 2014-06-12 20:12
source share