Manage-updates-with-lifecycle-methods

Tell us what’s happening:
I’m confused that when I click the update button don’t invoke the changeMessage function .

Your code so far


class Dialog extends React.Component {
  constructor(props) {
    super(props);
  }
  componentWillUpdate(nextProps) {
     console.log('Component is about to update...');
}
  // change code below this line
componentWillReceiveProps(nextProps) {
  console.log(this.props);
 console.log(nextProps(nextProps));
}
componentDidlUpdate() {
     console.log('Component is didUpdate...');
}
  // change code above this line
  render() {
    return <h1>{this.props.message}</h1>
  }
};

class Controller extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      message: 'First Message'
    };
    this.changeMessage = this.changeMessage.bind(this);
  }
  changeMessage() {
    this.setState({
      message: 'Second Message'
    });
  }
  render() {
    return (
      <div>
        <button onClick={this.changeMessage}>Update</button>
        <Dialog message={this.state.message}/>
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:

Hi @yangxia605

Have you checked the console for any errors?

I suspect the issue is probably because you’re trying to call nextProps as a function (in the Dialog class componentWillRecieveProps method) when it’s actually a plain object.

thank you so much. I have solved this problem.Maybe I should read more before do it.:slightly_frowning_face:

@yangxia605 is your code working after changed your nextProps issue.?