1. props
this.props
contains the props that were defined by the caller of this component. See Components and Props for an introduction to props.
In particular,this.props.children
is 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)
}
网友评论