I have a classic Flux pattern in my application, using fluxible
. An input's value
is tied to my component's prop, and its onChange
invokes an action, which in turn updates a store, which in turn passes a prop into my component:
class MyComponent extends React.Component {
handleChange(e) {
this.context.executeAction(persist, { value: e.target.value });
}
render() {
return <input value={this.props.value} onChange={this.handleChange.bind(this)}/>;
}
}
The problem I'm having is that when the store emits a change and the new value gets passed into my component, that causes it to re-render, and the input cursor position is lost (is moved to the end).
I know I can create a custom shouldComponentUpdate
method for my component, but doing so is somewhat tricky and definitely tedious for what I assume is a very frequently-occuring pattern.
Is there a well-established pattern for avoiding re-renders for controlled inputs?