所以我有下面列出的问题。我尝试删除 close()
和 resetForm()
,但这些似乎不是问题。我不知道如何解决这个问题
警告:无法对已卸载的组件执行 React 状态更新。这是一个空操作,但它表明您的应用程序中存在内存泄漏。要修复,请取消 useEffect 清理函数中的所有订阅和异步任务。 在 Formik (http://localhost:3000/static/js/0.chunk.js:42765:19)
<Formik
initialValues={{
project: project ? project.name : "",
}}
validationSchema={ProjectSchema}
onSubmit={async (values, { setSubmitting, resetForm }) => {
// send our project
const res = project
? await editProject(project.id, values)
: await addProject(values);
setSubmitting(false);
if (res) {
close();
}
resetForm();
}}
>
{({ values, handleChange, isSubmitting, isValid, resetForm }) => (
<StyledForm>
<Field
type="text"
name="project"
placeholder={project ? project.name : "Write your project..."}
onChange={handleChange}
value={values.project}
component={Input}
/>
<ButtonsWrapper>
<Button
contain
color="main"
type="submit"
disabled={!isValid || isSubmitting}
loading={loading ? loadingText : null}
>
{project ? "Edit Project" : "Add Project"}
</Button>
<Button
type="button"
color="red"
contain
onClick={() => {
close();
resetForm();
}}
>
Cancel
</Button>
</ButtonsWrapper>
<MessageWrapper>
<Message error show={error}>
{error}
</Message>
</MessageWrapper>
</StyledForm>
)}
</Formik>