useSubmit
The imperative version of <Form>
that lets you, the programmer, submit a form instead of the user.
import { useSubmit } from "@remix-run/react";
function SomeComponent() {
const submit = useSubmit();
return (
<Form
onChange={(event) => {
submit(event.currentTarget);
}}
/>
);
}
submit(targetOrData, options);
targetOrData
Can be any of the following:
HTMLFormElement
instance
<Form
onSubmit={(event) => {
submit(event.currentTarget);
}}
/>
FormData
instance
const formData = new FormData();
formData.append("myKey", "myValue");
submit(formData);
Plain object that will be serialized as FormData
submit({ myKey: "myValue" });
options
Options for the submission, the same as <Form>
props. All options are optional.
application/x-www-form-urlencoded
or multipart/form-data
. Default is application/x-www-form-urlencoded
.false
to submit using a fetcher instead of performing a navigationnavigate: false
false
.false
."route"
(relative to the route hierarchy) or "path"
(relative to the URL).ReactDOM.flushSync
call instead of the default React.startTransition
document.startViewTransition()
unstable_useViewTransitionState()
submit(data, {
action: "",
method: "post",
encType: "application/x-www-form-urlencoded",
preventScrollReset: false,
replace: false,
relative: "route",
});
Discussion
Related API