[英]React hooks: 'TypeError: Object is not a function'
I'm using React version 16.13.1.我正在使用 React 版本 16.13.1。
I'm getting 'TypeError: Object is not a function'我收到“类型错误:Object 不是函数”
Here is my code (error message seems to think something is wrong with line 7):这是我的代码(错误消息似乎认为第 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();
}
Here is my custom hook:这是我的自定义钩子:
import { useState } from 'react';
export const ProcessInput = value => {
const [val, setVal] = useState(value);
return {
val,
setVal,
bind: {
val,
onChange: event => {
setVal(event.target.value);
}
}
};
};
Thanks in advance for your help.在此先感谢您的帮助。
ProcessInput is returning an object, but you are destructuring it to an array. ProcessInput 返回 object,但您将其解构为数组。
Try this:尝试这个:
const {val, bind} = ProcessInput('');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.