123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- diff --git a/dist/hook.mjs b/dist/hook.mjs
- index 4f2ea0f6818194b906590f2467f788e66d3524d9..fcec224f19be119a922734e8a6fb7d1916921d8a 100644
- --- a/dist/hook.mjs
- +++ b/dist/hook.mjs
- @@ -7,7 +7,7 @@ import {
- useEffect,
- useRef,
- useState,
- - useTransition
- + useTransition,
- } from "react";
-
- // src/utils.ts
- @@ -17,8 +17,12 @@ var isNextNotFoundError = (e) => isError(e) && e.message === "NEXT_NOT_FOUND";
-
- // src/hook.ts
- var getActionStatus = (res) => {
- - const hasSucceded = typeof res.data !== "undefined";
- - const hasErrored = typeof res.validationError !== "undefined" || typeof res.serverError !== "undefined" || typeof res.fetchError !== "undefined";
- + const hasSucceded = typeof res?.data !== "undefined";
- + const hasErrored =
- + typeof res === "undefined" ||
- + typeof res.validationError !== "undefined" ||
- + typeof res.serverError !== "undefined" ||
- + typeof res.fetchError !== "undefined";
- const hasExecuted = hasSucceded || hasErrored;
- return { hasExecuted, hasSucceded, hasErrored };
- };
- @@ -49,12 +53,15 @@ var useAction = (clientCaller, cb) => {
- onExecute(input2);
- }
- return startTransition(() => {
- - return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
- - if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- - throw e;
- - }
- - setRes({ fetchError: e });
- - });
- + return executor
- + .current(input2)
- + .then((res2) => setRes(res2))
- + .catch((e) => {
- + if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- + throw e;
- + }
- + setRes({ fetchError: e });
- + });
- });
- }, []);
- const reset = useCallback(() => {
- @@ -68,17 +75,20 @@ var useAction = (clientCaller, cb) => {
- reset,
- hasExecuted,
- hasSucceded,
- - hasErrored
- + hasErrored,
- };
- };
- var useOptimisticAction = (clientCaller, initialOptData, cb) => {
- const [res, setRes] = useState({});
- const [input, setInput] = useState();
- - const [optState, syncState] = experimental_useOptimistic({ ...initialOptData, ...res.data, __isExecuting__: false }, (state, newState) => ({
- - ...state,
- - ...newState,
- - __isExecuting__: true
- - }));
- + const [optState, syncState] = experimental_useOptimistic(
- + { ...initialOptData, ...res.data, __isExecuting__: false },
- + (state, newState) => ({
- + ...state,
- + ...newState,
- + __isExecuting__: true,
- + })
- + );
- const executor = useRef(clientCaller);
- const onExecuteRef = useRef(cb?.onExecute);
- const { hasExecuted, hasSucceded, hasErrored } = getActionStatus(res);
- @@ -90,12 +100,15 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
- if (onExecute) {
- onExecute(input2);
- }
- - return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
- - if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- - throw e;
- - }
- - setRes({ fetchError: e });
- - });
- + return executor
- + .current(input2)
- + .then((res2) => setRes(res2))
- + .catch((e) => {
- + if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- + throw e;
- + }
- + setRes({ fetchError: e });
- + });
- },
- [syncState]
- );
- @@ -113,11 +126,8 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
- reset,
- hasExecuted,
- hasSucceded,
- - hasErrored
- + hasErrored,
- };
- };
- -export {
- - useAction,
- - useOptimisticAction
- -};
- +export { useAction, useOptimisticAction };
- //# sourceMappingURL=hook.mjs.map
|