如何防止在功能组件中重复反应?
当我使用反应式时,它总是像图像一样重复。 如何防止重复? 像这样
const Login = () => {
// ========= Loading ============
if (loading) {
return <Loading />;
}
// ========= Error ============
if (error) {
if (error.code === "auth/user-not-found") {
toast.error("User Not Found !");
} else if (error.code === "auth/wrong-password") {
toast.error("Password is Wrong !. ");
}
}
if (user) {return <></>}
};
export default Login;
When I use React-Toast, It always duplication like the Image.
How prevent the duplication?
Toast Duplication Like This
const Login = () => {
// ========= Loading ============
if (loading) {
return <Loading />;
}
// ========= Error ============
if (error) {
if (error.code === "auth/user-not-found") {
toast.error("User Not Found !");
} else if (error.code === "auth/wrong-password") {
toast.error("Password is Wrong !. ");
}
}
if (user) {return <></>}
};
export default Login;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至于我们没有问题的全部情况,我建议您注意这2件事:
toast.error
不同。那么,也许在其他地方重复吐司?如果对您无济于事,请提供更多详细信息(当您在页面上有2个吐司时,API部分,parent consonent时,使用
登录
)As far as we don't have the full picture of the question, I'd recommend to take your attention on these 2 things:
toast.error
. So maybe toast is duplicated in some other place?If it doesn't help you, please provide more details (scenario when you have 2 toasts on the page, api section, parent component where
Login
is used)