首页 > 解决方案 > 如何解决 Hooks 上的这个 React 类型错误?

问题描述

错误图片

    const isSignUp = false;
    const handleChange = () => {};
    const [showPassword, setShowPassword] = useState(false);

    const handlePassword = () =>
        setShowPassword((prevShowPassword) => !prevShowPassword);

我正在使用 usestate 实现密码显示/隐藏功能,但我不明白为什么会出现此错误。帮忙看看怎么解决?

标签: javascriptreactjsreact-hookstypeerror

解决方案


解决了 !

当我有这个错误时:

import useState from "react";

当我把它改成这个时它得到了解决:

import { useState } from "react";

推荐阅读