1

Below is my sample code

var Test = React.createClass({ componentDidMount: function(){ //do something } render: function() { return ( <div id="testDiv"> <Header messages={this.props.mesage} /> {this.props.children} <Footer /> </div> ); } }); 

I will do something in componentDidMount. When the this.props.children, the componentDidMount will not run, why?

How can I run function when this.props.children has changed every time?

1 Answer 1

2

componentDidMount is run only once when components is mounted. You should use componentWillUpdate which is called immediately before rendering when new props or state are being received or componentWillReceiveProps which is invoked before a mounted component receives new props

Sign up to request clarification or add additional context in comments.

1 Comment

Really appreciated. I never use componentWillUpdate, so I totally forget it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.