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
Copy file name to clipboardExpand all lines: packages/hooks/src/useRequest/docs/basic/index.en-US.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,8 @@ Of course, the difference between `refresh` and `refreshAsync` is the same as `r
103
103
104
104
## Change data immediately
105
105
106
+
### optimisticData
107
+
106
108
`useRequest` provides `mutate`, which can immediate modify the `data`.
107
109
108
110
The usage of `mutate` is consistent with `React.setState`, supports: `mutate(newData)` and `mutate((oldData) => newData)`.
@@ -111,6 +113,10 @@ In the following example, we demonstrate a scenario of `mutate`.
111
113
112
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.
113
115
116
+
### error rollback
117
+
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.
0 commit comments