如何解决ReactJS:如何在页面的子组件中使用 useState?
我正在尝试在表单中使用 useState,但出现以下错误:
Can't perform a React state update on an unmounted component. This is a no-op,but it indicates a memory leak in your application. To fix,cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
这是组件的代码:
import React,{useState} from "react";
import {
Container,FormWrap,Icon,FormContent,Form,FormH1,Formlabel,FormInput,FormButton
} from "./SignupElements";
const SignUp = () => {
const [email,setEmail] = useState('');
const [username,setUsername] = useState('');
const [name,setName] = useState('');
const [firstSurname,setFirstSurname] = useState('');
const [secondSurname,setSecondSurname] = useState('');
const [password,setPassword] = useState('');
return (
<>
<Container>
<FormWrap>
<Icon to="/">App</Icon>
<FormContent>
<Form action="#">
<FormH1>Sign up</FormH1>
<Formlabel htmlFor="for">Email</Formlabel>
<FormInput onChange={(e) => setEmail(e.target.value)} type="email" required />
<Formlabel htmlFor="for">Username</Formlabel>
<FormInput onChange={(e) => setUsername(e.target.value)} type="text" required />
<Formlabel htmlFor="for">Name</Formlabel>
<FormInput onChange={(e) => setName(e.target.value)} type="text" required />
<Formlabel htmlFor="for">First Surname</Formlabel>
<FormInput onChange={(e) => setFirstSurname(e.target.value)} type="text" required />
<Formlabel htmlFor="for">Second Surname</Formlabel>
<FormInput onChange={(e) => setSecondSurname(e.target.value)} type="text" />
<Formlabel htmlFor="for">Password</Formlabel>
<FormInput onChange={(e) => setPassword(e.target.value)} type="password" required />
<FormButton type="submit">Sign Up</FormButton>
</Form>
</FormContent>
</FormWrap>
</Container>
</>
);
};
export default SignUp;
react app 有不同的页面(直到现在是 index 和 sing-up),也许是相关信息,但我不知道如何解决。
如果有人知道如何解决它,我将非常感谢您的回答。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。