@@ -37,11 +37,11 @@ import { createFormData } from "../utilities";
3737
3838export type SubmitFunctionOptions = Parameters < SubmitFunction > [ 1 ] ;
3939
40- export interface UseRemixFormOptions < T extends FieldValues >
41- extends UseFormProps < T > {
40+ export interface UseRemixFormOptions < TFieldValues extends FieldValues , TContext = any , TTransformedValues = TFieldValues >
41+ extends UseFormProps < TFieldValues , TContext , TTransformedValues > {
4242 submitHandlers ?: {
43- onValid ?: SubmitHandler < T > ;
44- onInvalid ?: SubmitErrorHandler < T > ;
43+ onValid ?: SubmitHandler < TTransformedValues > ;
44+ onInvalid ?: SubmitErrorHandler < TFieldValues > ;
4545 } ;
4646 submitConfig ?: SubmitFunctionOptions ;
4747 submitData ?: FieldValues ;
@@ -52,29 +52,29 @@ export interface UseRemixFormOptions<T extends FieldValues>
5252 stringifyAllValues ?: boolean ;
5353}
5454
55- export const useRemixForm = < T extends FieldValues > ( {
55+ export const useRemixForm = < TFieldValues extends FieldValues , TContext = any , TTransformedValues = TFieldValues > ( {
5656 submitHandlers,
5757 submitConfig,
5858 submitData,
5959 fetcher,
6060 stringifyAllValues = true ,
6161 ...formProps
62- } : UseRemixFormOptions < T > ) => {
62+ } : UseRemixFormOptions < TFieldValues , TContext , TTransformedValues > ) => {
6363 const [ isSubmittedSuccessfully , setIsSubmittedSuccessfully ] = useState ( false ) ;
6464 const basename = useHref ( "/" ) ;
6565 const actionSubmit = useSubmit ( ) ;
6666 const actionData = useActionData ( ) ;
6767 const submit = fetcher ?. submit ?? actionSubmit ;
6868 // biome-ignore lint/suspicious/noExplicitAny: <explanation>
6969 const data : any = fetcher ?. data ?? actionData ;
70- const methods = useForm < T > ( { ...formProps , errors : data ?. errors } ) ;
70+ const methods = useForm ( { ...formProps , errors : data ?. errors } ) ;
7171 const navigation = useNavigation ( ) ;
7272 // Either it's submitted to an action or submitted to a fetcher (or neither)
7373 const isSubmittingForm = useMemo (
7474 ( ) =>
7575 Boolean (
7676 ( navigation . state !== "idle" && navigation . formData !== undefined ) ||
77- ( fetcher ?. state !== "idle" && fetcher ?. formData !== undefined ) ,
77+ ( fetcher ?. state !== "idle" && fetcher ?. formData !== undefined ) ,
7878 ) ,
7979 [ navigation . state , navigation . formData , fetcher ?. state , fetcher ?. formData ] ,
8080 ) ;
@@ -92,7 +92,7 @@ export const useRemixForm = <T extends FieldValues>({
9292 const onSubmit = useMemo (
9393 ( ) =>
9494 (
95- data : T ,
95+ data : TTransformedValues ,
9696 // biome-ignore lint/suspicious/noExplicitAny: <explanation>
9797 e : any ,
9898 formEncType ?: FormEncType ,
@@ -121,11 +121,11 @@ export const useRemixForm = <T extends FieldValues>({
121121 ) ;
122122
123123 // eslint-disable-next-line @typescript-eslint/no-empty-function
124- const onInvalid = useMemo ( ( ) => ( ) => { } , [ ] ) ;
124+ const onInvalid = useMemo ( ( ) => ( ) => { } , [ ] ) ;
125125
126126 // React-hook-form uses lazy property getters to avoid re-rendering when properties
127127 // that aren't being used change. Using getters here preservers that lazy behavior.
128- const formState : FormState < T > = useMemo (
128+ const formState : FormState < TFieldValues > = useMemo (
129129 ( ) => ( {
130130 get isDirty ( ) {
131131 return methods . formState . isDirty ;
@@ -175,7 +175,7 @@ export const useRemixForm = <T extends FieldValues>({
175175 const reset = useMemo (
176176 ( ) =>
177177 (
178- values ?: T | DefaultValues < T > | undefined ,
178+ values ?: TFieldValues | DefaultValues < TFieldValues > | undefined ,
179179 options ?: KeepStateOptions ,
180180 ) => {
181181 setIsSubmittedSuccessfully ( false ) ;
@@ -187,8 +187,8 @@ export const useRemixForm = <T extends FieldValues>({
187187 const register = useMemo (
188188 ( ) =>
189189 (
190- name : Path < T > ,
191- options ?: RegisterOptions < T > & {
190+ name : Path < TFieldValues > ,
191+ options ?: RegisterOptions < TFieldValues > & {
192192 disableProgressiveEnhancement ?: boolean ;
193193 } ,
194194 ) => {
@@ -242,14 +242,14 @@ export const useRemixForm = <T extends FieldValues>({
242242 return hookReturn ;
243243} ;
244244
245- export type UseRemixFormReturn < T extends FieldValues > = UseFormReturn < T > & {
245+ export type UseRemixFormReturn < TFieldValues extends FieldValues = FieldValues , TContext = any , TTransformedValues = TFieldValues > = UseFormReturn < TFieldValues , TContext , TTransformedValues > & {
246246 handleSubmit : ReturnType < typeof useRemixForm > [ "handleSubmit" ] ;
247247 reset : ReturnType < typeof useRemixForm > [ "reset" ] ;
248248 register : ReturnType < typeof useRemixForm > [ "register" ] ;
249249} ;
250250
251- interface RemixFormProviderProps < T extends FieldValues >
252- extends Omit < UseFormReturn < T > , "handleSubmit" | "reset" > {
251+ interface RemixFormProviderProps < TFieldValues extends FieldValues = FieldValues , TContext = any , TTransformedValues = TFieldValues >
252+ extends Omit < UseFormReturn < TFieldValues , TContext , TTransformedValues > , "handleSubmit" | "reset" > {
253253 children : ReactNode ;
254254 // biome-ignore lint/suspicious/noExplicitAny: <explanation>
255255 handleSubmit : any ;
@@ -258,20 +258,20 @@ interface RemixFormProviderProps<T extends FieldValues>
258258 // biome-ignore lint/suspicious/noExplicitAny: <explanation>
259259 reset : any ;
260260}
261- export const RemixFormProvider = < T extends FieldValues > ( {
261+ export const RemixFormProvider = < TFieldValues extends FieldValues = FieldValues , TContext = any , TTransformedValues = TFieldValues > ( {
262262 children,
263263 ...props
264- } : RemixFormProviderProps < T > ) => {
264+ } : RemixFormProviderProps < TFieldValues , TContext , TTransformedValues > ) => {
265265 return < FormProvider { ...props } > { children } </ FormProvider > ;
266266} ;
267267
268- export const useRemixFormContext = < T extends FieldValues > ( ) => {
269- const methods = useFormContext < T > ( ) ;
268+ export const useRemixFormContext = < TFieldValues extends FieldValues , TContext = any , TTransformedValues = TFieldValues > ( ) => {
269+ const methods = useFormContext < TFieldValues , TContext , TTransformedValues > ( ) ;
270270 return {
271271 ...methods ,
272272 // biome-ignore lint/suspicious/noExplicitAny: <explanation>
273273 handleSubmit : methods . handleSubmit as any as ReturnType <
274- UseFormHandleSubmit < T >
274+ UseFormHandleSubmit < TFieldValues , TTransformedValues >
275275 > ,
276276 } ;
277277} ;
0 commit comments