"use client"; import React, {useState} from "react"; import clsx from "clsx"; type InputType = 'text' | 'password'; function PasswordInput({ placeholder, onChange, onBlur, name, error, ref }: { // 用于react-hook-form时,推荐使用useForm的 defaultValues 对整个表单设置默认值 placeholder: string; // 用于react-hook-form时,React 事件处理器类型定义中的“双变(bivariance)”特性 和返回值void的兼容性,使typescript没有提示类型错误 onChange: (e: React.ChangeEvent) => void; onBlur: (e: React.ChangeEvent) => void; name: string; error?: string; ref?: React.Ref; }) { const [inputType, setInputType] = useState('password'); const changeType = () => { if(inputType === 'text') { setInputType('password'); } if(inputType === 'password') { setInputType('text'); } }; return (
{error &&

{error}

}
); } // 设置 displayName,便于调试 PasswordInput.displayName = 'PasswordInput'; export default PasswordInput;