Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Restrict Form.encType #37

Merged
merged 4 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/neat-snakes-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@next-fetch/core-plugin": patch
"@next-fetch/react-query": patch
"@next-fetch/swr": patch
---

Restrict FormProps to explicitly prevent users from using unsupported encTypes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:smart:

we can support multipart once we have a good api for that :just-right:

4 changes: 3 additions & 1 deletion packages/@next-fetch/core-plugin/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function useForm<Input, Config>(
hook: HookWithFormSubmission<Input, Config>,
config?: Config
): {
formProps: HTMLProps<HTMLFormElement>;
formProps: HTMLProps<HTMLFormElement> & {
encType?: "application/x-www-form-urlencoded";
};
} {
const { trigger, meta } = hook;

Expand Down
5 changes: 4 additions & 1 deletion packages/@next-fetch/react-query/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function useForm<Data, Error, Input, Context>(
hook: HookWithFormSubmission<Data, Error, Input, Context>,
config?: UseMutationOptions<Data, Error, Input, Context>
): {
formProps: HTMLProps<HTMLFormElement>;
formProps: HTMLProps<HTMLFormElement> & {
encType?: "application/x-www-form-urlencoded";
};
} {
return useForm_({ meta: hook.meta, trigger: hook.mutate }, config);
}
Expand All @@ -40,6 +42,7 @@ export function Form<Data, Error, Input, Context>({
React.PropsWithChildren<{
mutation: HookWithFormSubmission<Data, Error, Input, Context>;
mutationConfig?: UseMutationOptions<Data, Error, Input, Context>;
encType?: "application/x-www-form-urlencoded";
}>) {
const { formProps } = useForm(mutation, mutationConfig);
return createElement("form", { ...formProps, ...props }, props.children);
Expand Down
5 changes: 4 additions & 1 deletion packages/@next-fetch/swr/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function useForm<Data, Error>(
hook: HookWithFormSubmission<Data, Error>,
config?: SWRMutationConfiguration<Data, Error>
): {
formProps: HTMLProps<HTMLFormElement>;
formProps: HTMLProps<HTMLFormElement> & {
encType?: "application/x-www-form-urlencoded";
};
} {
return useForm_(hook, config);
}
Expand All @@ -40,6 +42,7 @@ export function Form<Data, Error>({
React.PropsWithChildren<{
mutation: HookWithFormSubmission<Data, Error>;
mutationConfig?: SWRMutationConfiguration<Data, Error>;
encType?: "application/x-www-form-urlencoded";
}>) {
const { formProps } = useForm(mutation, mutationConfig);
return createElement("form", { ...formProps, ...props }, props.children);
Expand Down