TanStackT
TanStack5mo ago
12 replies
skinny-azure

Sharing form type to custom hooks for cleaner code

Hey folks, I have read the philosophy of forms and previous discussion on why generic are bad. But I do want to ask what could go wrong if setup the form this way

export const { useAppForm , … } = creatFormHook({ … }):

function useSetupAppForm(props: FormSetupProps) {

     return useAppForm({ ….formOptions, onSubmit, … }) // pass static values for TS inference
}

type AppForm = ReturnType<typeof useSetupAppForm> // <—— is this going to be problematic


function MyForm(props: FormSetupProps) {

    Const form = useSetupAppForm(props);
    
   useFormNavigation(form) // <— pass form to a custom hook and avoid cluttering the MyForm
}
Was this page helpful?