【问题标题】:Got Error: Uncaught TypeError: handleChange is not a function得到错误:未捕获的类型错误:handleChange 不是函数
【发布时间】:2022-07-30 04:16:20
【问题描述】:

我想在输入标签中使用句柄函数。但是当我在主页上调用这个函数时,它会显示错误。

主要代码

const Input = ({ placeholder, name, type, value, handleChange }) => (
    <input
        placeholder={placeholder}
        type={type}
        step="0.0001"
        value={value}
        onChange={(e) => handleChange(e, name)}
        className="my-2 w-full rounded-sm p-2 outline-none bg-transparent text-white 
        border-none text-sm white-glassmorphism"
    />
);

句柄 Change 的声明位置:

const handleChange = (e, name) => {
    setformData((prevState) => ({ ...prevState, [name]: e.target.value }));
};

【问题讨论】:

  • 请提供更多详细信息,完整代码您如何使用Input

标签: react-native blockchain web3-react


【解决方案1】:

你可以这样使用

const MyTextInput = ({ value, name, type, onChange }) => {
  return (
    <TextInput
      value={value}
      onChangeText={text => onChange({ name, type, text })}
    />
  );
};

然后在需要使用TextInput的时候使用它

handleChange(event) {
    const {name, type, text} = event;
    .....
}

<MyTextInput name="username" type="text" value={this.state.username} onChange={this.handleChange}}>
<MyTextInput name="password" type="number" value={this.state.password} onChange={this.handleChange}}>

【讨论】:

    猜你喜欢
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 2019-06-06
    相关资源
    最近更新 更多