Skip to content

Commit

Permalink
chore(website): document isTransitioning and isPending statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Aug 14, 2024
1 parent 1d89f4c commit c6fa08e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
23 changes: 23 additions & 0 deletions website/docs/execution/hooks/check-action-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
sidebar_position: 6
description: Check the current action execution status.
---

# Check action status

You can check the current action execution status using either the `status` property or the shorthand properties returned by all hooks.

## Via `status` property

`status` property is a discriminated string, so it can only be one of the following values at any given time: `idle`, `executing`, `hasSucceeded`, `hasErrored`.


## Via shorthand properties

Shorthand properties are convenience booleans that are `true` if the corresponding action status string is of the same value. Other than `isIdle`, `isExecuting`, `hasSucceeded` and `hasErrored`, also `isTransitioning` and `isPending` are returned by all three hooks.

### Difference between `isExecuting`, `isTransitioning`, and `isPending`

The difference between these three properties is that `isExecuting` is `true` when the Server Action is actually been executed, `isTransitioning` is true when the under the hood value from `useTransition` hook is `true` (so, when the transition is in progress), and `isPending` is `true` when `isExecuting` or `isTransitioning` are `true`.

The safest and recommended way to check if the action is in progress is to use `isPending` property, because using just `isExecuting` could cause some weird glitches when navigation functions like `redirect` are used inside the Server Action.
2 changes: 1 addition & 1 deletion website/docs/execution/hooks/hook-callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Here is the full list of callbacks, with their behavior explained. All of them a
| `onExecute?` | `"executing"` |
| `onSuccess?` | `"hasSucceeded"` |
| `onError?` | `"hasErrored"` |
| `onSettled?` | `"hasSucceeded"` or `"hasErrored"` (after `onSuccess` or `onError` call) |
| `onSettled?` | `"hasSucceeded"` or `"hasErrored"` |
2 changes: 2 additions & 0 deletions website/docs/execution/hooks/useaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ As you can see, here we display a greet message after the action is performed, i
| `reset` | `() => void` | Programmatically reset `input` and `result` object with this function. |
| `status` | [`HookActionStatus`](/docs/types#hookresult) | The action current status. |
| `isIdle` | `boolean` | True if the action status is `idle`. |
| `isTransitioning` | `boolean` | True if the transition status from the `useTransition` hook used under the hood is `true`. |
| `isExecuting` | `boolean` | True if the action status is `executing`. |
| `isPending` | `boolean` | True if either `isTransitioning` or `isExecuting` are `true`. |
| `hasSucceeded` | `boolean` | True if the action status is `hasSucceeded`. |
| `hasErrored` | `boolean` | True if the action status is `hasErrored`. |

Expand Down
2 changes: 2 additions & 0 deletions website/docs/execution/hooks/useoptimisticaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export default function TodosBox({ todos }: Props) {
| `reset` | `() => void` | Programmatically reset `input` and `result` object with this function. |
| `status` | [`HookActionStatus`](/docs/types#hookresult) | The action current status. |
| `isIdle` | `boolean` | True if the action status is `idle`. |
| `isTransitioning` | `boolean` | True if the transition status from the `useTransition` hook used under the hood is `true`. |
| `isExecuting` | `boolean` | True if the action status is `executing`. |
| `isPending` | `boolean` | True if either `isTransitioning` or `isExecuting` are `true`. |
| `hasSucceeded` | `boolean` | True if the action status is `hasSucceeded`. |
| `hasErrored` | `boolean` | True if the action status is `hasErrored`. |

Expand Down
2 changes: 2 additions & 0 deletions website/docs/execution/hooks/usestateaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ You can pass an optional initial result to `useStateAction`, with the `initResul
| `result` | [`HookResult`](/docs/types#hookresult) | When the action gets called via `execute`, this is the result object. |
| `status` | [`HookActionStatus`](/docs/types#hookresult) | The action current status. |
| `isIdle` | `boolean` | True if the action status is `idle`. |
| `isTransitioning` | `boolean` | True if the transition status from the `useTransition` hook used under the hood is `true`. |
| `isExecuting` | `boolean` | True if the action status is `executing`. |
| `isPending` | `boolean` | True if either `isTransitioning` or `isExecuting` are `true`. |
| `hasSucceeded` | `boolean` | True if the action status is `hasSucceeded`. |
| `hasErrored` | `boolean` | True if the action status is `hasErrored`. |

Expand Down

0 comments on commit c6fa08e

Please sign in to comment.