Hydration failed
Unanswered
Siberian posted this in #help-forum
SiberianOP
Hello, I'm using a form and when submitting I encounter the notorious console error:
Here is the relevant client component code that is causing the error:
Thanks in advance.
Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client.
<form
+ method="POST"
- method={null}
action={function bound dispatchActionState}
className="grid gap-2 relative"
>
Here is the relevant client component code that is causing the error:
import { ActionResult } from "@/app/types";
import { ReactNode, useActionState } from "react";
import Card from "./Card";
export default function Form({
children,
formAction,
title,
subtitle,
styles,
}: {
children: ReactNode;
formAction: (_: any, formData: FormData) => Promise<ActionResult>;
title: string;
subtitle: string;
styles?: string;
}) {
const [state, action, isLoading] = useActionState(formAction, {
message: "",
success: false,
});
return (
<Card title={title} subtitle={subtitle} styles={styles || "max-w-md"}>
<form method="POST" action={action} className="grid gap-2 relative">
{children}
</form>
</Card>
);
}
Thanks in advance.
9 Replies
Asian black bear
Try removing the explicit method prop.
@Asian black bear Try removing the explicit method prop.
SiberianOP
That results in me getting this hydration error on submit:
autofill-information={"overall type: UNKNOWN_TYPE\nhtml type: HTML_TYPE_UNSPECIFIED\n..."}
- title={"overall type: UNKNOWN_TYPE\nhtml type: HTML_TYPE_UNSPECIFIED\nserver type: NO..."}
- autofill-prediction="UNKNOWN_TYPE"
Asian black bear
This looks like Chrome.
Try a different browser to confirm whether it's an issue with your code or the browser.
@Asian black bear Try a different browser to confirm whether it's an issue with your code or the browser.
SiberianOP
Alright, I'll commit treason and open up Binge.
@Asian black bear Try a different browser to confirm whether it's an issue with your code or the browser.
SiberianOP
Ohh my bad I've accidently removed a
"use server"
from my server actions file, thanks for helping though.@Siberian Ohh my bad I've accidently removed a `"use server"` from my server actions file, thanks for helping though.
Crying rn lol, I typed "Weird, If the function you're passing to useActionState() is a Server Action I would bet It works. Are you sure you're marking it with "use server"?" and then did
ctrl + x
when I read it might be chrome and I didn't want to sound stupid...@LuisLl Crying rn lol, I typed "*Weird, If the function you're passing to useActionState() is a Server Action I would bet It works. Are you sure you're marking it with "use server"?*" and then did `ctrl + x` when I read it might be chrome and I didn't want to sound stupid...
SiberianOP
Yeah still a beginner 😛
You're good