1. props
this.propscontains the props that were defined by the caller of this component. See Components and Props for an introduction to props.
In particular,this.props.childrenis a special prop, typically defined by the child tags in the JSX expression rather than in the tag itself.
也就是說Props應該是該組件的調用者使用的。
2. state
The state contains data specific to this component that may change over time. The state is user-defined, and it should be a plain JavaScript object.
If you don't use it inrender(), it shouldn't be on the state. For example, you can put timer IDs directly on the instance.
state包含的數據應該都是用到render()里面的,如果不是用到render(),你可以考慮定義為props(需要外部調用者傳進來)或者該組件的一個普通屬性(例如組件內部用到的定時器等等)
3 自定義的屬性
組件用到的一些對象,不需要外部傳入切不參與渲染,那么就可以定義為普通的組件屬性。
例如組件用到了定時器
setupInterval() {
this.interval= setInterval(() => {
//some stuff
}, 5000)
}