-
Hi I was wondering if by submitting the form via butto is normal that all the page re-renders or there is something wrong. This is my code: // Ext
import {
Controller,
SubmitHandler,
useForm,
FormProvider,
} from "react-hook-form";
import {
Box,
Button,
Card,
CardActions,
CardContent,
MenuItem,
TextField,
Typography,
} from "@mui/material";
import { zodResolver } from "@hookform/resolvers/zod";
// Types
import { LoginFormInputs } from "../types";
// Scss
import "../static/scss/#.scss";
import BrandName from "../components/BrandName";
import { LoginSchema } from "../schemas";
import { FormInputText } from "../components/form/FormInputTextField";
const Login: React.FC = () => {
// Form
const defaultValues: LoginFormInputs = {
username: "",
password: ""
};
const methods = useForm<LoginFormInputs>({
resolver: zodResolver(LoginSchema),
defaultValues,
});
const onSubmit: SubmitHandler<LoginFormInputs> = async (
data: LoginFormInputs
) => {
console.log(data);
};
return (
<Box className="login-itemsbox">
<Box className="title-box">
<Typography>
<BrandName />
</Typography>
</Box>
<Box className="card-form-box">
<FormProvider {...methods}>
<Card component="form" onSubmit={methods.handleSubmit(onSubmit)}>
<CardContent>
<FormInputText name="username" label="username" />
<FormInputText name="password" label="password" />
</CardContent>
<CardActions>
<Button type="submit" variant="contained">
Login
</Button>
</CardActions>
</Card>
</FormProvider>
</Box>
<Box className="small-footer-box">Small Footer</Box>
</Box>
);
};
export default Login; PS: I'm not using the watch function |
Beta Was this translation helpful? Give feedback.
Answered by
leapful
Feb 23, 2023
Replies: 1 comment 6 replies
-
Please provide a codesandbox to re-produce the issue. Without a detail context on your issue, no on knows what is the page that has been re-rendered by submit handler. |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
IronCub3
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
@IronCub3
Please provide a codesandbox to re-produce the issue. Without a detail context on your issue, no on knows what is the page that has been re-rendered by submit handler.