Skip to content

Commit 45e0f96

Browse files
committedOct 12, 2024··
refactor(hooks): deprecate executeOnMount
1 parent 7fffa24 commit 45e0f96

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

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

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import type { MaybePromise, Prettify } from "./utils.types";
66
* Type of base utils object passed to `useAction`, `useOptimisticAction` and `useStateAction` hooks.
77
*/
88
export type HookBaseUtils<S extends Schema | undefined> = {
9+
/**
10+
* @deprecated Actions should not execute on component mount, since they're used to mutate data.
11+
*/
912
executeOnMount?: (undefined extends S
1013
? { input?: undefined }
1114
: {

‎website/docs/execute-actions/hooks/hook-base-utils.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ description: Hook base utilities shared by all hooks.
77

88
Hook base utilities are a set of properties shared by all hooks.
99

10-
## `executeOnMount?`
10+
## `executeOnMount?` \[deprecated\]
11+
12+
:::warning deprecated
13+
This property is deprecated and will be removed in the next major version. Actions should be used only for data mutations, so executing them on component mount is not recommended.
14+
:::
1115

1216
`executeOnMount` is an optional object that, if passed to the hook, will `execute` the action when the component is mounted. It expects an `input` property of the same type as the input of the action and an optional `delayMs` property, which is the number of milliseconds to wait before executing the action (defaults to 0).

0 commit comments

Comments
 (0)
Please sign in to comment.