update child component when parent component changes

前端 未结 1 1361
太阳男子
太阳男子 2021-01-23 19:19

I\'m kind of new to React js. I have two questions. Here I go

Question 1

I wanted to update(re-render) the child component when I update(re-render

相关标签:
1条回答
  • 2021-01-23 20:03
    this.props.user = res.data.user; 
    

    You can't assign to props. Props are passed from a parent. Set the user in the state and pass the state to your child component like so:

    <ABCD {...this.props} user={this.state.user} />
    

    In your child component you will now have access to this.props.user. Also the this.forceUpdate() will not be needed then.

    0 讨论(0)
提交回复
热议问题