Skip to content

Commit

Permalink
docs: update docs/React/Building components.md
Browse files Browse the repository at this point in the history
  • Loading branch information
qiufeihong2018 committed May 8, 2024
1 parent 18d2c33 commit f61b937
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/React/Building components.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function HelloComponent(props) /* context */{

有状态的组件也就是组件内部存在维护的数据,在类创建的方式中通过`this.state`进行访问

当调用`this.setState`修改组件的状态时,组价会再次会调用`render()`方法进行重新渲染
当调用`this.setState`修改组件的状态时,组件会再次会调用`render()`方法进行重新渲染

通过继承`React.Component`创建一个时钟示例如下:

Expand Down
2 changes: 1 addition & 1 deletion docs/React/High order components.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default (WrappedComponent) => {

这里需要注意的是,高阶组件可以传递所有的`props`,但是不能传递`ref`

如果向一个高阶组件添加`refe`引用,那么`ref` 指向的是最外层容器组件实例的,而不是被包裹的组件,如果需要传递`refs`的话,则使用`React.forwardRef`,如下:
如果向一个高阶组件添加`ref`引用,那么`ref` 指向的是最外层容器组件实例的,而不是被包裹的组件,如果需要传递`refs`的话,则使用`React.forwardRef`,如下:

```jsx
function withLogging(WrappedComponent) {
Expand Down
2 changes: 1 addition & 1 deletion docs/React/React refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

- 传入字符串,使用时通过 this.refs.传入的字符串的格式获取对应的元素
- 传入对象,对象是通过 React.createRef() 方式创建出来,使用时获取到创建的对象中存在 current 属性就是对应的元素
- 传入函数,该函数会在 DOM 被挂载时进行回调,这个函数会传入一个 元素对象,可以自己保存,使用时,直接拿到之前保存的元素对象即可
- 传入函数,该函数会在 DOM 被挂载时进行回调,这个函数会传入一个元素对象,可以自己保存,使用时,直接拿到之前保存的元素对象即可
- 传入hook,hook是通过 useRef() 方式创建,使用时通过生成hook对象的 current 属性就是对应的元素


Expand Down
2 changes: 1 addition & 1 deletion docs/React/class_function component.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class ProfilePage extends React.Component {
}
```

两者看起来实现功能是一致的,但是在类组件中,输出`this.props.user``Props ``React `中是不可变的所以它永远不会改变,但是 `this` 总是可变的,以便您可以在 `render` 和生命周期函数中读取新版本
两者看起来实现功能是一致的,但是在类组件中,输出`this.props.user``Props ``React `中是不可变的,所以它永远不会改变,但是 `this` 总是可变的,以便您可以在 `render` 和生命周期函数中读取新版本

因此,如果我们的组件在请求运行时更新。`this.props` 将会改变。`showMessage `方法从“最新”的 `props` 中读取 `user`

Expand Down
2 changes: 1 addition & 1 deletion docs/React/communication.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Parent extends React.Component {
</PriceContext.Provider>
```

如果想要获取`Provider`传递的数据,可以通过`Consumer`组件或者或者使用`contextType`属性接收,对应分别如下:
如果想要获取`Provider`传递的数据,可以通过`Consumer`组件或者使用`contextType`属性接收,对应分别如下:

```jsx
class MyClass extends React.Component {
Expand Down

0 comments on commit f61b937

Please sign in to comment.