ProNextJS / forms-management-yt

Code for the Forms Management video on YouTube
58 stars 6 forks source link

Unable to add interactivity #3

Closed tuppers360 closed 5 months ago

tuppers360 commented 5 months ago

Hi

Firstly thanks do much for this code and the videos that come with it, it has really helped a lot.

I am struggling to pass const { isSubmitting } = form.formState; to a button component or use const { pending } = useFormStatus(); to display a spinner when submitting a form.

I believe its due to how the form is submitted using: ref={formRef} action={formAction} onSubmit={(evt) => { form.handleSubmit(() => { formAction(new FormData(formRef.current!)); })(evt); }}

Is there something I am missing here?

Thanks

jherr commented 5 months ago

This is a known issue. There will be a new useAction hook that unifies useFormState and useFormStatus.

tuppers360 commented 5 months ago

Super thanks for replying! I was going a little stir crazy trying to figure that out!

Using your youtube video with onSubmit={() => { form.handleSubmit(() => formRef?.current?.submit()); }}

instead seems to work but not sure it isn't causing any issues elsewhere

jherr commented 5 months ago

You should check the most recent code on that, some folks found issues with submitting after a navigation and this was the fix:

        onSubmit={(evt) => {
          evt.preventDefault();
          form.handleSubmit(() => {
            formAction(new FormData(formRef.current!));
          })(evt);
        }}
kam-st commented 4 months ago

I tried using most recent code. This causes form not to reset. Following code works well for resetting.

 onSubmit={(evt) => {
          evt.preventDefault();
          form.handleSubmit(() => {
            formRef.current?.submit();
          })(evt);
        }}

Sorry, but not sure what bug following code is fixing. Would you be able to help. So I don't miss issues.

formAction(new FormData(formRef.current!));