我使用的是 React 版本 16.13.1。
我收到“类型错误:对象不是函数”
这是我的代码(错误消息似乎认为第 7 行有问题):
import React, { useState } from 'react';
import fb from '../config/firebase';
import ProcessInput from './customHooks/processInput';
const DashBoard = ({ level, newUser }) => {
const [val, bind] = ProcessInput('');
const handleChange = (e) => {
e.preventDefault();
}
Run Code Online (Sandbox Code Playgroud)
这是我的自定义钩子:
import { useState } from 'react';
export const ProcessInput = value => {
const [val, setVal] = useState(value);
return {
val,
setVal,
bind: {
val,
onChange: event => {
setVal(event.target.value);
}
}
};
}; …Run Code Online (Sandbox Code Playgroud)