Skip to content

Commit

Permalink
docs: modify docs subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
97vack committed Sep 30, 2024
1 parent 5a60f83 commit 1b7f4e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/intro/useSubscribe.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ toc: content

# Subscribe to latest value

Using form model data **model** to control form controls through dot assignment. However, this will not cause the entire view to be re-rendered, thus achieving part of the performance optimization. If you directly use model.xx to render the latest value outside the form item, it may not achieve the expected effect.
Using form model data **model** to control form controls through point assignment. However, this will not cause the entire view to be re-rendered, which means that it cannot be consumed as a state variable externally. This is also part of achieving performance optimization. If you want to directly use model.xx to render the latest value outside the form item, it may not achieve the expected effect.

Therefore, we can use the **useSubscribe** hook to solve this problem.
Therefore, we can use **useSubscribe** hook to solve this problem.

**useSubscribe** uses a deep comparison algorithm, which means that as long as the new value and the old value are exactly the same, no matter how deep the hierarchy is, it will not re-render.

### <Mdh>Basic Usage</Mdh>

Expand Down
4 changes: 3 additions & 1 deletion docs/intro/useSubscribe.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ toc: content

# 订阅最新值

使用表单模型数据 _model_ 通过点赋值可以对表单控件进行受控。然而,这不会引起整体视图的重新渲染,从而实现性能优化的一部分。如果你直接使用 model.xx 在表单项外部渲染最新的值,它可能无法达到预期的效果。
使用表单模型数据 _model_ 通过点赋值可以对表单控件进行受控。然而这不会引起整体视图的重新渲染,也就是说在外部无法让它作为一个state状态变量去消费。这也是实现性能优化的一部分。如果你想直接使用 model.xx 在表单项外部渲染最新的值,它可能无法达到预期的效果。

因此,我们可以借助 _useSubscribe_ hook 来解决这个问题。

_useSubscribe_ 采用深度对比算法,也就是说只要新的value和旧的value不管层级多深只要值完全相同那它就不会re-render。

### <Mdh>基本用法</Mdh>

使用 _useSubscribe_ 订阅某个表单控件的值。
Expand Down
2 changes: 2 additions & 0 deletions docs/intro/useWatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ toc: content

**React Form Simple** provides form watch functionality, which is very useful for handling specific logic when certain form fields change.

**useWatch** uses a deep comparison algorithm, which means that as long as the new value and the old value are exactly the same, no matter how deep the level is, it will not trigger the listener function.

### <Mdh>Basic Usage</Mdh>

Use **useWatch** to monitor changes in a specific field.
Expand Down
2 changes: 2 additions & 0 deletions docs/intro/useWatch.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ toc: content

_React Form Simple_ 提供表单监听操作,对于在某些表单项字段变化后需要处理特定逻辑的情况非常有用。

_useWatch_ 采用深度对比算法,也就是说只要新的value和旧的value不管层级多深只要值完全相同那它就不会触发listener函数。

### <Mdh>基本用法</Mdh>

使用 _useWatch_ 监听某个字段的变化。
Expand Down

0 comments on commit 1b7f4e7

Please sign in to comment.