I would like some help wrapping my head round a react/reflux pattern that I have going on, and if its acceptable.
I have a form component which renders several form elements such as the example below. The form component is connected to a Reflux Store, where the data is located for the form elements.
exports.InputField = React.createClass({
getInitialState: function(){
return {
value: this.props.initialValue
}
},
onChange: function(e){
this.setState({value: e.target.value});
// this is being throttled.
Actions.SomeAction(this.props.name, e.target.value);
},
render: function(){
var value = this.state.value;
return (
<input type="text" value={value} onChange={this.onChange}/>
)
}
})
In the given example, the user types in the field, and this in turn will trigger an ajax request to save the data, usually responding with a status code of 200.
Should I be
this.trigger
'ing inside my store when this completes? This would causesetState
on the form to be invoked on every debounced key press. Is that bad?Am I allowed to fire events from the store, such as
Actions.FieldUpdated
and listen to that within the field component?
Theres a couple of examples of react/reflux examples of things being updated with submit buttons, but I cant find any examples of this with onChange.