I can't rerender the parent component from the child component - I pass componentDidMount as props to child class, then I call it there, and expect the parent to rerender. The render function is called, but the content remains unchanged. What's wrong?
var Parent = React.createClass({
getInitialState: function () { return {content: 'clean'}; },
componentDidMount: function () {
this.setState({content: 'changed!'});
},
render: function () {
return React.createElement('div', {rerender: this.componentDidMount.bind(this)}, this.state.content);
}
});
var Child = React.createClass({
render: function () {
return React.createElement('div', {onClick: this.handleClick}, 'click me');
},
handleClick: function () {
this.props.rerender();
}
});
ReactDOM.render(
React.createElement(ReactRouter.Router, {history: ReactRouter.browserHistory},
React.createElement(ReactRouter.Route, {path: '/parent', component: Parent})
)
, document.getElementById('content'));
setStatein the parent component - Daniel Lizikthis.componentDidMountas an event callback :) you should create own function to handle thatrerenderin parent component.. and of course it won't chance since when the parent component mount the state will becontent: changed!and when you handle click it will call that same function so state will be the same.. - Hardy