UNPKG

askeroo

Version:

A modern CLI prompt library with flow control, history navigation, and conditional prompts

34 lines 1.16 kB
import { useEffect } from "react"; /** * Hook for plugins with autoSubmit=true that need to auto-submit * without requiring user interaction. * * @param onSubmit - The submit callback to trigger * @param state - The current plugin state * @param delay - Optional delay in milliseconds before submitting (default: 0ms for immediate) */ export function useAutoSubmit(onSubmit, state = "active", delay = 0) { useEffect(() => { if (onSubmit && state === "active") { if (delay > 0) { const timer = setTimeout(onSubmit, delay); return () => clearTimeout(timer); } else { // Submit immediately after render onSubmit(undefined); } } }, [onSubmit, state, delay]); } /** * Common hook for resetting field submitted state when field becomes active again */ export const useFieldReset = (disabled, submitted, setSubmitted) => { useEffect(() => { if (!disabled && submitted) { setSubmitted(false); } }, [disabled, submitted, setSubmitted]); }; //# sourceMappingURL=use-auto-submit.js.map