我正在将withFormik与material-ui一起用于表单验证。我想用api请求返回的数据填充表单以更新表单。
const addname = withFormik({
enableReinitialize: true,
mapPropsToValues: ({
name,
}) => {
return {
name: name || '',
};
},
validationSchema: Yup.object().shape({
name: Yup.string().required("Please specify Name of an Person"),
}),
handleSubmit: (values, { props, setStatus, setFieldError }) => {
axios({
url: '/save/',
method: 'POST',
data: {
name: values.name,
}
}).then((res) => {
console.log(res)
}).catch((err) => {
console.log({ "error": err })
})
},
})(Form);