Skip to content

Commit

Permalink
add: class/instance properties
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Oct 27, 2019
1 parent 47793d1 commit 182a0e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api-reference/003-other-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ this.setState((state) => {

## forceUpdate
component.forceUpdate(callback)
> 通常你应该避免使用 forceUpdate(),尽量在 render() 中使用 this.props 和 this.state。
## resources
- https://stackoverflow.com/questions/48563650/does-react-keep-the-order-for-state-updates/48610973#48610973
Expand Down
10 changes: 10 additions & 0 deletions docs/api-reference/005-class-props.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# class properties

## defaultProps
- defaultProps 可以为 Class 组件添加默认 props。
- 这一般用于 props 未赋值,但又不能为 null 的情况。

## displayName
- displayName 字符串多用于调试消息。
- 通常,你不需要设置它,因为它可以根据函数组件或 class 组件的名称推断出来。
- 如果调试时需要显示不同的名称或创建高阶组件,请参阅使用 displayname 轻松进行调试了解更多。
14 changes: 14 additions & 0 deletions docs/api-reference/006-instance-props.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# instance properties
> 实例属性。

## props
- this.props 包括被该组件调用者定义的 props。欲了解 props 的详细介绍,请参阅组件 & Props。
- 需特别注意,this.props.children 是一个特殊的 prop,通常由 JSX 表达式中的子组件组成,而非组件本身定义。

## state
- 组件中的 state 包含了随时可能发生变化的数据。state 由用户自定义,它是一个普通 JavaScript 对象。
- 如果某些值未用于渲染或数据流(例如,计时器 ID),则不必将其设置为 state。此类值可以在组件实例上定义。
- 欲了解关于 state 的更多信息,请参阅 State & 生命周期。
- 永远不要直接改变 this.state,因为后续调用的 setState() 可能会替换掉你的改变。
- 请把 this.state 看作是不可变的。

0 comments on commit 182a0e8

Please sign in to comment.