Better single fetch support for explicit loader/action return types #10244
-
We always define explicit return types, and single fetch is making this a bit tougher than it needs to be on our loaders and actions. With Unfortunately this means type DataWithResponseInit<T> = ReturnType<typeof data<T>>; An official solution would be great. Just re-exporting |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
deprecating json() and not exporting DataWithResponseInit means that I can't easily upgrade remix because I have to do a manual update to several hundred files instead of being able to search and replace. |
Beta Was this translation helpful? Give feedback.
-
Agreed this is making it so updating to i.e. export async function action({
request,
}: Route.ActionArgs) {
const formData = await request.formData();
const email = String(formData.get("email"));
const password = String(formData.get("password"));
const errors = {};
if (!email.includes("@")) {
errors.email = "Invalid email address";
}
if (password.length < 12) {
errors.password =
"Password should be at least 12 characters";
}
if (Object.keys(errors).length > 0) {
return data({ errors }, { status: 400 });
}
// Redirect to dashboard if validation is successful
return redirect("/dashboard");
}
export default function Signup(_: Route.ComponentProps) {
let fetcher = useFetcher();
let errors = fetcher.data?.errors; // This is typed as any
return (
<fetcher.Form method="post">
<p>
<input type="email" name="email" />
{errors?.email ? <em>{errors.email}</em> : null}
</p>
<p>
<input type="password" name="password" />
{errors?.password ? (
<em>{errors.password}</em>
) : null}
</p>
<button type="submit">Sign Up</button>
</fetcher.Form>
);
} If you do ^ with |
Beta Was this translation helpful? Give feedback.
-
Please try adding |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this will help your case, but you could use the optional type argument for the
|
Beta Was this translation helpful? Give feedback.
-
React Router now exports this type, which works for us! import type { UNSAFE_DataWithResponseInit } from "react-router"; |
Beta Was this translation helpful? Give feedback.
React Router now exports this type, which works for us!