React Formik 给出无法读取未定义的属性(读取‘fullName’)错误
2022-04-08
4389
我使用 formik react mui 技术并且此代码块给出
Cannot read properties of undefined (reading 'fullName')
const formik = useFormik({
initalValues: {
fullName: "",
email:"",
phone:"",
select:"",
message:""
},
onSubmit: (values)=> {
console.log(JSON.stringify(values))
},
})
<form onSubmit={formik.handleSubmit}>
<Grid container spacing={3}>
<Grid item md={6} xs={12}>
<TextField fullWidth name='fullName' value={formik.values.fullName} onChange={formik.handleChange} id="fullName" label="Ad Soyad" variant="outlined" />
</Grid>
1个回答
您将“initialValues”拼写错误为“initalValues”,因此 Formik 没有读取它。
MrFullStack
2022-04-09