Skip to content

Commit 9af8d76

Browse files
authored
docs(useRequest): update cancel desc (alibaba#1836)
1 parent 4fe0fa5 commit 9af8d76

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

packages/hooks/src/useRequest/doc/basic/basic.en-US.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ We have modified the user name, but we do not want to wait for the request to be
9797

9898
<!-- <code src="./demo/formatResult.tsx" /> -->
9999

100-
## Cancel request
100+
## Cancel response
101101

102-
`useRequest` provides a `cancel` function, which can cancel the request. At the same time, `useRequest` will automatically cancel the current request at the following timing:
102+
`useRequest` provides a `cancel` function, which will **ignore** the data and erros returned by the current promise
103103

104-
- When the component is unmounting, the ongoing request will be cancelled
105-
- Race cancellation, when the previous request has not returned, if the next request is initiated, the previous request will be cancelled
104+
**Note: Calling `cancel` doesn't cancel the execution of promise**
105+
106+
At the same time, `useRequest` will automatically ignore the response at the following timing:
107+
108+
- When the component is unmounting, the ongoing promise
109+
- Race cancellation, when the previous promise has not returned, if the next promise is initiated, the previous promise will be ignored
106110

107111
<code src="./demo/cancel.tsx" />
108112

@@ -154,7 +158,7 @@ const {
154158
| refresh | Use the last params, call `run` again | `() => void` |
155159
| refreshAsync | Use the last params, call `runAsync` again | `() => Promise<TData>` |
156160
| mutate | Mutate `data` directly | `(data?: TData / ((oldData?: TData) => (TData / undefined))) => void` |
157-
| cancel | Cancel the current running request | `() => void` |
161+
| cancel | Ignore the current promise response | `() => void` |
158162

159163
### Options
160164

packages/hooks/src/useRequest/doc/basic/basic.zh-CN.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ const { loading, run, runAsync } = useRequest(service, {
9797

9898
<!-- <code src="./demo/formatResult.tsx" /> -->
9999

100-
## 取消请求
100+
## 取消响应
101101

102-
`useRequest` 提供了 `cancel` 函数,可以取消当前正在进行的请求。同时 `useRequest` 会在以下时机自动取消当前请求:
102+
`useRequest` 提供了 `cancel` 函数,用于**忽略**当前 promise 返回的数据和错误
103103

104-
- 组件卸载时,取消正在进行的请求
105-
- 竞态取消,当上一次请求还没返回时,又发起了下一次请求,则会取消上一次请求
104+
**注意:调用 `cancel` 函数并不会取消 promise 的执行**
105+
106+
同时 `useRequest` 会在以下时机自动忽略响应:
107+
108+
- 组件卸载时,正在进行的 promise
109+
- 竞态取消,当上一次 promise 还没返回时,又发起了下一次 promise,则会忽略上一次 promise 的响应
106110

107111
<code src="./demo/cancel.tsx" />
108112

@@ -154,7 +158,7 @@ const {
154158
| refresh | 使用上一次的 params,重新调用 `run` | `() => void` |
155159
| refreshAsync | 使用上一次的 params,重新调用 `runAsync` | `() => Promise<TData>` |
156160
| mutate | 直接修改 `data` | `(data?: TData / ((oldData?: TData) => (TData / undefined))) => void` |
157-
| cancel | 取消当前正在进行的请求 | `() => void` |
161+
| cancel | 忽略当前 Promise 的响应 | `() => void` |
158162

159163
### Options
160164

0 commit comments

Comments
 (0)