Skip to content

Commit

Permalink
refactor(hooks): deprecate executeOnMount
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Oct 12, 2024
1 parent 7fffa24 commit 45e0f96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/next-safe-action/src/hooks.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import type { MaybePromise, Prettify } from "./utils.types";
* Type of base utils object passed to `useAction`, `useOptimisticAction` and `useStateAction` hooks.
*/
export type HookBaseUtils<S extends Schema | undefined> = {
/**
* @deprecated Actions should not execute on component mount, since they're used to mutate data.
*/
executeOnMount?: (undefined extends S
? { input?: undefined }
: {
Expand Down
6 changes: 5 additions & 1 deletion website/docs/execute-actions/hooks/hook-base-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ description: Hook base utilities shared by all hooks.

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

## `executeOnMount?`
## `executeOnMount?` \[deprecated\]

:::warning deprecated
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.
:::

`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 comments on commit 45e0f96

Please sign in to comment.