ReactJS state vs prop

后端 未结 6 977
予麋鹿
予麋鹿 2021-01-29 17:59

This may be treading that line between answerable and opinionated, but I\'m going back and forth as to how to structure a ReactJS component as complexity grows and could use som

6条回答
  •  一向
    一向 (楼主)
    2021-01-29 18:30

    From React doc

    props are immutable: they are passed from the parent and are "owned" by the parent. To implement interactions, we introduce mutable state to the component. this.state is private to the component and can be changed by calling this.setState(). When the state is updated, the component re-renders itself.

    From TrySpace: when props (or state) are updated (via setProps/setState or parent) the component re-renders as well.

提交回复
热议问题