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
* lint fix
* improve docs
* minor improvement to types
* rationalise manage-resource-state into a smaller number of api functions with clear abstraction
* consistent API for all actions of resource and context arguments
* more precise variable names for slices
* clearly demarcate private and public actions and stub public action dependencies
* minor fix to test label for consistency
* ensure resource slice always represents correct future state, docs, tests
* reinstate async function
Copy file name to clipboardExpand all lines: docs/api/hooks.md
+18-11Lines changed: 18 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -35,17 +35,24 @@ export const Feed = () => {
35
35
36
36
As well as returning actions that act on the resource (i.e. update and refresh), `useResource` returns four different properties that indicate the state of the resource. These four are `data`, `loading`, `error` and `promise`. `useResource` will return different combinations of these four properties depending on the state of the resource. The table below shows all the possible combinations.
It is important to note that loading can be true even when there is an error. In that case, promise will be null because there is no Suspense support on the server. Developers should give priority to loading when deciding between loading or error states for their components. Promises/errors should only ever be thrown on the client
47
-
48
-
It also acceps some options as second argument to customise the behaviour, like `routerContext`.
Where `-prev-` indicates the field will remain unchanged from any previous state, possibly the inital state.
50
+
51
+
It is important to note
52
+
* The timeout state is essentially a hung loading state, with the difference that `promise = null` and `error != null`. Developers should give priority to `loading` when deciding between loading or error states for their components. Promises/errors should only ever be thrown on the client.
53
+
* The `promise` reflects the last operation, either async or explicit update. Update will clear `error`, set `data`. It will also set a `promise` consistent with that `data` so long as no async is `loading`. When `loading` the `promise` will always reflect the future `data` or `error` from the pending async.
54
+
55
+
Additionaly `useResource` accepts additional arguments to customise behaviour, like `routerContext`.
49
56
Check out [this section](../resources/usage.md) for more details on how to use the `useResource` hook.
0 commit comments