CONNECTBACKBONETOREACT
Without connectBackboneToReact we would have to write this every time we used a Backbone.Model:
class MyComponent extends React.Component {
componentWillMount() {
this.props.model.on('change', this.updateState, this);
}
componentWillReceiveProps(nextProps) {
this.updateState(nextProps.model);
}
componentWillUnmount() {
this.props.model.off('change', this.updateState, this);
}
updateState(model) {
this.setState({ data: model.toJSON() });
}
render() {
return (
{this.state.data.property}
)
}
}
// Usage