update child component when parent component changes

前端 未结 1 1380
太阳男子
太阳男子 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:

    
    

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

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