I have a top-level component ( RegisrationPage
) with the condition that it is transmitted status / details to reset the lower-level components ( InputField
, Dropdown
, Datepicker
). Lower-level components change state RegistrationPage
using callbacks.
Problem: PureRenderMixin does not work, since I need to bind a state change call that is passed to lower-level components.
Question: how to make it PureRenderMixin
work in the most elegant way?
Explain this with code:
InputBlock:
const React = require('react'),
PureRenderMixin = require('react-addons-pure-render-mixin');
module.exports = React.createClass({
mixins: [PureRenderMixin],
propTypes: {
input: React.PropTypes.string,
onChange: React.PropTypes.func
},
render() {
//PROBLEM - is re-rendered each time , since onChange callback each time is an different object due bind method call
}
});
RegistrationPage:
RegistrationPage = React.createClass({
render() {
return CreateFragment({
email: <InputBlock
input={this.state.email}
onChange={this._onFieldChange.bind(self, 'email')}/>,
firstName: <InputBlock
input={this.state.firstName}
onChange={this._onFieldChange.bind(self, 'firstName')}/>,
.........
});
},
_onFieldChange(key, event) {
AppActionCreators.saveRegisterProgress(this.state);
}
})
My workaround: just pass inputFieldName
as an extra property and bind it to the lower level component.