daily-toolset
Version:
A lightweight, versatile collection of TypeScript utility functions for everyday development needs. Simplify and streamline your Node.js, React, and Next.js projects with a powerful suite of well-organized helpers for strings, arrays, dates, objects, and
27 lines (26 loc) • 1.33 kB
TypeScript
import { ReactNode } from "react";
import { z, ZodEffects, ZodObject, ZodRawShape } from "zod";
type InputValue = string | string[] | number | null;
type FormProviderProps = {
children: ReactNode;
};
export declare function FormProvider({ children }: FormProviderProps): import("react/jsx-runtime").JSX.Element;
type UnwrapZodSchema<T> = T extends ZodEffects<infer U> ? UnwrapZodSchema<U> : T;
type InferZodSchema<T> = T extends ZodObject<ZodRawShape> ? z.infer<T> : never;
export declare function useForm<Schema extends ZodObject<ZodRawShape> | ZodEffects<ZodObject<ZodRawShape>> | undefined, DefaultValues = Schema extends undefined ? Record<string, unknown> : InferZodSchema<UnwrapZodSchema<Schema>>>(props?: {
schema?: Schema;
defaultValues?: DefaultValues;
errors?: Partial<Record<keyof DefaultValues, string>>;
mode?: "controlled" | "uncontrolled";
}): {
formValues: DefaultValues;
formErrors: {};
updateValue: () => void;
validateField: () => Promise<void>;
} | {
formValues: InferZodSchema<UnwrapZodSchema<Schema>> | DefaultValues;
formErrors: Partial<Record<keyof InferZodSchema<UnwrapZodSchema<Schema>>, string>>;
updateValue: (name: string | undefined, value: any) => void;
validateField: (name: string | undefined, value: InputValue) => Promise<void>;
};
export {};