Skip to content

Commit fbd3a67

Browse files
committed
refactor(hooks): readd isPending shorthand status property as deprecated
1 parent 89d0e70 commit fbd3a67

File tree

6 files changed

+10
-3
lines changed

6 files changed

+10
-3
lines changed

apps/playground/src/app/(examples)/optimistic-hook/addtodo-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const AddTodoForm = ({ todos }: Props) => {
3939
return (
4040
<>
4141
<form
42-
className="flex flex-col mt-8 space-y-4"
42+
className="mt-8 flex flex-col space-y-4"
4343
onSubmit={(e) => {
4444
e.preventDefault();
4545
const formData = new FormData(e.currentTarget);

packages/next-safe-action/src/hooks-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const getActionShorthandStatusObject = ({
4747
return {
4848
isIdle: status === "idle",
4949
isExecuting: status === "executing",
50+
isPending: status === "executing",
5051
isTransitioning,
5152
hasSucceeded: status === "hasSucceeded",
5253
hasErrored: status === "hasErrored",

packages/next-safe-action/src/hooks.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export type HookShorthandStatus = {
5151
isIdle: boolean;
5252
isExecuting: boolean;
5353
isTransitioning: boolean;
54+
/**
55+
* @deprecated Use `isExecuting` instead.
56+
*/
57+
isPending: boolean;
5458
hasSucceeded: boolean;
5559
hasErrored: boolean;
5660
hasNavigated: boolean;

website/docs/execute-actions/hooks/useaction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ As you can see, here we display a greet message after the action is performed, i
7777
- `isIdle`: true if the action status is `idle`.
7878
- `isTransitioning`: true if the transition status from the `useTransition` hook used under the hood is `true`.
7979
- `isExecuting`: true if the action status is `executing`.
80+
- `isPending`: same as `isExecuting` (deprecated).
8081
- `hasSucceeded`: true if the action status is `hasSucceeded`.
8182
- `hasErrored`: true if the action status is `hasErrored`.
8283
- `hasNavigated`: true if a `next/navigation` function was called inside the action.

website/docs/execute-actions/hooks/useoptimisticaction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export default function TodosBox({ todos }: Props) {
131131
- `isIdle`: true if the action status is `idle`.
132132
- `isTransitioning`: true if the transition status from the `useTransition` hook used under the hood is `true`.
133133
- `isExecuting`: true if the action status is `executing`.
134+
- `isPending`: same as `isExecuting` (deprecated).
134135
- `hasSucceeded`: true if the action status is `hasSucceeded`.
135136
- `hasErrored`: true if the action status is `hasErrored`.
136137
- `hasNavigated`: true if a `next/navigation` function was called inside the action.

website/docs/migrations/v7-to-v8.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ const result = await boundAction(input);
9292

9393
The deprecated `executeOnMount` hook functionality has been removed in v8. Server Actions should be used only for mutations, so it doesn't make sense to execute them on mount. Or at least, it shouldn't be a common case and, above all, a library job. If you still need to do it, just use `useEffect()` to trigger the execution, however you want.
9494

95-
### ⚠️ Removal of `isPending` shorthand status property
95+
### 🔄 Deprecation of `isPending` shorthand status property
9696

97-
The `isPending` shorthand status property has been removed from hooks return objects in v8. Having both `isExecuting` and `isPending` properties was a bit confusing, so now both the `isExecuting` property and `"executing"` status value include the transition state of the action execution.
97+
The `isPending` shorthand status property is now deprecated, and will be removed in a future version. Having both `isExecuting` and `isPending` properties is a bit confusing, so now both the `isExecuting` property and `"executing"` status value include the transition state of the action execution. `isPending` right now is just an alias for `isExecuting`.
9898

9999
### ✨ Type-checked metadata
100100

0 commit comments

Comments
 (0)