diff --git a/packages/next-safe-action/src/hooks.ts b/packages/next-safe-action/src/hooks.ts index 58daf337..3448f945 100644 --- a/packages/next-safe-action/src/hooks.ts +++ b/packages/next-safe-action/src/hooks.ts @@ -3,7 +3,7 @@ import type { InferIn, Schema } from "@decs/typeschema"; import { isNotFoundError } from "next/dist/client/components/not-found.js"; import { isRedirectError } from "next/dist/client/components/redirect.js"; -import { useCallback, useEffect, useOptimistic, useRef, useState, useTransition } from "react"; +import * as React from "react"; import {} from "react/experimental"; import type { SafeAction } from "."; import type { MaybePromise } from "./utils"; @@ -76,13 +76,13 @@ const useActionCallbacks = ( reset: () => void, cb?: HookCallbacks ) => { - const onExecuteRef = useRef(cb?.onExecute); - const onSuccessRef = useRef(cb?.onSuccess); - const onErrorRef = useRef(cb?.onError); - const onSettledRef = useRef(cb?.onSettled); + const onExecuteRef = React.useRef(cb?.onExecute); + const onSuccessRef = React.useRef(cb?.onSuccess); + const onErrorRef = React.useRef(cb?.onError); + const onSettledRef = React.useRef(cb?.onSettled); // Execute the callback when the action status changes. - useEffect(() => { + React.useEffect(() => { const onExecute = onExecuteRef.current; const onSuccess = onSuccessRef.current; const onError = onErrorRef.current; @@ -121,14 +121,14 @@ export const useAction = ( safeAction: SafeAction, callbacks?: HookCallbacks ) => { - const [, startTransition] = useTransition(); - const [result, setResult] = useState>(DEFAULT_RESULT); - const [input, setInput] = useState>(); - const [isExecuting, setIsExecuting] = useState(false); + const [, startTransition] = React.useTransition(); + const [result, setResult] = React.useState>(DEFAULT_RESULT); + const [input, setInput] = React.useState>(); + const [isExecuting, setIsExecuting] = React.useState(false); const status = getActionStatus(isExecuting, result); - const execute = useCallback( + const execute = React.useCallback( (input: InferIn) => { setInput(input); setIsExecuting(true); @@ -151,7 +151,7 @@ export const useAction = ( [safeAction] ); - const reset = useCallback(() => { + const reset = React.useCallback(() => { setResult(DEFAULT_RESULT); }, []); @@ -182,19 +182,19 @@ export const useOptimisticAction = ( reducer: (state: Data, input: InferIn) => Data, callbacks?: HookCallbacks ) => { - const [, startTransition] = useTransition(); - const [result, setResult] = useState>(DEFAULT_RESULT); - const [input, setInput] = useState>(); - const [isExecuting, setIsExecuting] = useState(false); + const [, startTransition] = React.useTransition(); + const [result, setResult] = React.useState>(DEFAULT_RESULT); + const [input, setInput] = React.useState>(); + const [isExecuting, setIsExecuting] = React.useState(false); - const [optimisticData, setOptimisticState] = useOptimistic>( + const [optimisticData, setOptimisticState] = React.useOptimistic>( initialOptimisticData, reducer ); const status = getActionStatus(isExecuting, result); - const execute = useCallback( + const execute = React.useCallback( (input: InferIn) => { setInput(input); setIsExecuting(true); @@ -218,7 +218,7 @@ export const useOptimisticAction = ( [setOptimisticState, safeAction] ); - const reset = useCallback(() => { + const reset = React.useCallback(() => { setResult(DEFAULT_RESULT); }, []); diff --git a/packages/next-safe-action/tsconfig.json b/packages/next-safe-action/tsconfig.json index 4ef58d21..9c1363bd 100644 --- a/packages/next-safe-action/tsconfig.json +++ b/packages/next-safe-action/tsconfig.json @@ -22,8 +22,8 @@ "esModuleInterop": true, "resolveJsonModule": true, "incremental": false, - "noEmit": true + "noEmit": true, }, "exclude": ["node_modules"], - "include": ["tsup.config.ts", "./src/**/*.ts"] + "include": ["tsup.config.ts", "./src/**/*.ts"], }