You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* type: format result type
* type: sync
* type: format result type
* chore: upgrade v2
* feat: upgrade use-request plugin
* docs: add use-request format result docs
* docs: add migrate v2
* docs: opt
* docs: demo
* docs: add route
* test: use-request plugin unit test
In order to have good type hints and subsequent expansion in the v2 version of useRequest plug-in system, we have redesigned the usage of plugin option. You only need to make simple changes to achieve migration.
12
+
13
+
## v1 use
14
+
15
+
```typescript
16
+
const { data } =useRequest(
17
+
() =>serviceFn(),
18
+
{
19
+
...option,
20
+
...pluginOption,
21
+
},
22
+
[useFormatterPlugin, ...otherPlugins],
23
+
)
24
+
```
25
+
26
+
## v2 use
27
+
28
+
```typescript
29
+
const { data } =useRequest(
30
+
() =>serviceFn(),
31
+
{
32
+
...option,
33
+
pluginOptions: {
34
+
...pluginOption,
35
+
},
36
+
},
37
+
[useFormatterPlugin, ...otherPlugins],
38
+
)
39
+
```
40
+
41
+
Just migrate it to `pluginOptions` based on the original plugin option.
Copy file name to clipboardExpand all lines: packages/hooks/src/useRequest/docs/basic/index.en-US.md
+2-8Lines changed: 2 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,7 @@ In the following example, we demonstrate a scenario of `mutate`.
113
113
114
114
We have modified the user name, but we do not want to wait for the request to be successful before giving feedback to the user. Instead, modify the data directly, then call the modify request in background, and provide additional feedback after the request returns.
115
115
116
-
### error rollback`1.7.7.alpha.4`
116
+
### error rollback
117
117
118
118
When you use `mutate`, it is possible that the remote data change fails after the optimistic data is displayed to the user. In this case, you can enable `rollbackOnError`, which restores the local cache to its previous state, ensuring that the user sees Got the correct data.
119
119
@@ -149,12 +149,6 @@ If we set `options.manual = false`, the parameters of calling `service` for the
149
149
title=""
150
150
desc=""> </demo>
151
151
152
-
## Format the request data
153
-
154
-
Since `useRequest` needs to guarantee a good plug-in system, format is too invasive for the system, the formatting here is `useFormatResult`, format data to `useFormatResult` after the request data is completed, `useFormatResult` can well support `typescript` type prompt. <br />
155
-
156
-
<ahref="/docs/hooks/en/useFormatResult/" >Jump to useFormatResult</a>
157
-
158
152
## API
159
153
160
154
```ts
@@ -205,7 +199,7 @@ const {
205
199
| initialData | Init data |`TData`\|`undefined`|
206
200
| manual | <ul><li> The default is `false`. That is, the service is automatically executed during initialization.</li><li>If set to `true`, you need to manually call `run` or `runAsync` to trigger execution. </li></ul> |`boolean`|`false`|
207
201
| defaultParams | The parameters passed to the service at the first default execution |`TParams`| - |
208
-
| formatResult | Format the request results, which recommend to use `useFormatResult`|`(response: TData) => any`| - |
202
+
| formatResult | Format the request results,v1 which recommend to use `useFormatResult`|`(response: TData) => FormatData`| - |
209
203
| onBefore | Triggered before service execution |`(params: TParams) => void`| - |
210
204
| onSuccess | Triggered when service resolve |`(data: TData, params: TParams) => void`| - |
211
205
| onError | Triggered when service reject |`(e: Error, params: TParams) => void`| - |
0 commit comments