ReactJS state vs prop

后端 未结 6 976
予麋鹿
予麋鹿 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:16

    A reading from Thinking in React:

    Let's go through each one and figure out which one is state. Simply ask three questions about each piece of data:

    1. Is it passed in from a parent via props? If so, it probably isn't state.
    2. Does it change over time? If not, it probably isn't state.

    3. Can you compute it based on any other state or props in your component? If so, it's not state.

提交回复
热议问题