Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend union type of form methods for new Form component #11764

Closed
wants to merge 2 commits into from
Closed

Extend union type of form methods for new Form component #11764

wants to merge 2 commits into from

Conversation

maurer2
Copy link

@maurer2 maurer2 commented Apr 7, 2024

Hello, when using the experimental Form component with Nextjs server actions, the following warning is outputted in the browser console:

Warning: Prop `method` did not match. Server: "POST" Client: "post"

Example

const methods = useForm<SearchFormValues>({
  defaultValues: {
    // default values
  },
  progressive: true,
});

const [formState, action] = useFormState(namOfServerAction, null);

<Form
  action={action}
  control={methods.control}
  method="post"
>
  // fields
</Form>

Changing "post" to "POST" removes the warning in the browser console, but triggers a TypeScript warning as the method type only contains 'post' | 'put' | 'delete' This change adds uppercase variants of the existing methods to the union type.

Cheers

Hello, when using the new form component with Nextjs server actions, a warning is outputted in the browser console.

```
const methods = useForm<SearchFormValues>({
    defaultValues: {
    // default values
    },
    progressive: true,action
  });
const [formState, action] = useFormState(namOfAction(), null);

<Form
        action={action}
        control={methods.control}
        method="post"
      >
     //
</Form>
```

```
Warning: Prop `method` did not match. Server: "POST" Client: "post"
```

Changing "post" to "POST" removes the warning in the browser console, but triggers a TypeScript warning as the method props only contains 'post' | 'put' | 'delete'; This change adds "POST" to the union type.

Cheers
Copy link

codesandbox bot commented Apr 7, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@maurer2 maurer2 closed this Apr 7, 2024
@maurer2 maurer2 deleted the patch-1 branch April 7, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant