-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
68 additions
and
202 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: usePrevious | ||
group: | ||
title: State | ||
path: /state | ||
order: 600 | ||
--- | ||
|
||
# usePrevious | ||
|
||
保存上一次渲染时状态的 Hook | ||
|
||
|
||
## 代码演示 | ||
|
||
### 基本用法 | ||
|
||
<code src="./demo/demo1.tsx" /> | ||
|
||
### 使用 compare function | ||
|
||
<code src="./demo/demo2.tsx" /> | ||
|
||
## API | ||
``` | ||
const previousState: T = usePrevious<T>( | ||
state: T, | ||
compareFunction: (prev: T | undefined, next: T) => boolean | ||
); | ||
``` | ||
|
||
### Result | ||
|
||
| 参数 | 说明 | 类型 | | ||
|------|----------|------| | ||
| previousState | 上次 state 的值 | T | | ||
|
||
### Params | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
|---------|----------|------------------------|--------| | ||
| state | 需要记录变化的值 | T | - | | ||
| compareFunction | 可选,自定义值变化的规则 | (prev: T \| undefined, next: T) => boolean | - | |
This file was deleted.
Oops, something went wrong.