UNPKG

next-era

Version:

Welcome to **Next Era**! A comprehensive library designed to supercharge your **Next.js** applications with powerful utilities and significant performance optimizations. Build faster, more efficient, and feature-rich Next.js projects with ease.

18 lines (17 loc) 775 B
import { useActionState as useActionStateReact, useEffect, useState, } from "react"; /** * Enhanced useActionState of React to allow update action's state manually by setState function. * @param action action function to dispatch form's data * @param initialState initial state of the form * @param permalink permalink of the form * @returns state, dispatch, isPending, setState */ const useActionState = (action, initialState, permalink) => { const [state, formAction, isPending] = useActionStateReact(action, initialState, permalink); const [customState, setCustomState] = useState(state); useEffect(() => { setCustomState(state); }, [state]); return [customState, formAction, isPending, setCustomState]; }; export default useActionState;