iway1 / react-ts-form

https://react-ts-form.com
MIT License
2.01k stars 33 forks source link

Form prop in FormContainer not available. When passing a react-hook-form form to the FormContainer, the form property is not available. This is making the library difficult to use, becuase its hard to access the submitting value of the form. #87

Closed acollazomayer closed 1 year ago

acollazomayer commented 1 year ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

iway1 commented 1 year ago

You should be able to use react-hook-form's useFormContext() already:

import {useFormContext} from 'react-hook-form';

function FormContainer({children, onSubmit}:{children: ReactNode, onSubmit: ()=>void}) {
  const form = useFormContext();
}

This brings up a good point though - this could be documented better.

Just updated the documentation to make this more obvious, I think useFormContext already as easy as possible to use as is, so won't pass the prop to the form container or anything.

Let me know if that doesn't solve your problem, though.

iway1 commented 1 year ago

gonna close, if the above solution didn't work let me know

acollazomayer commented 1 year ago

@iway1 its not working properly, FE when you use an async function the isSubmitting value from the state never changes back to false

acollazomayer commented 1 year ago

@iway1 Did you check this, can you please show examples on how to handle async submissions. Because I am not able to make this work.