React Formik 给出 Cannot read properties of undefined (reading 'fullName') 错误
React Formik gives Cannot read properties of undefined (reading 'fullName') error
我使用 formik react mui tech 并且这个代码块给出了
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>
您将“initialValues”拼错为“initalValues”,所以 Formik 没有阅读它。
我使用 formik react mui tech 并且这个代码块给出了
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>
您将“initialValues”拼错为“initalValues”,所以 Formik 没有阅读它。