简体   繁体   English

反应钩子:'TypeError:Object 不是函数'

[英]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.

相关问题 React 和 hooks - 获取 TypeError: Object(...) is not a function - React and hooks - Getting TypeError: Object(...) is not a function React Hooks Todo App 'TypeError: Object(...) is not a function' 错误 - React Hooks Todo App 'TypeError: Object(...) is not a function' error React Hooks: Uncaught TypeError: setData({...}) is not a function - React Hooks: Uncaught TypeError: setData({...}) is not a function 类型错误:setCartCount 不是 function - React Hooks - Redux - TypeError: setCartCount is not a function - React Hooks - Redux TypeError: Object(...) 在使用 useHistory() 钩子时不是函数 - TypeError: Object(...) is not a function when using useHistory() hooks reactjs TypeError:使用钩子时Object(…)不是函数 - reactjs TypeError: Object(…) is not a function when using hooks 我收到错误消息:```TypeError: Object(...) is not a function``` in my react app- 第一次尝试使用钩子 - I'm getting the error: ```TypeError: Object(…) is not a function``` in my react app- trying to use hooks for the first time TypeError: Object(…) is not a function (React) - TypeError: Object(…) is not a function (React) 使用 React Hooks 时 TypeError dispatcher.useState 不是函数 - TypeError dispatcher.useState is not a function when using React Hooks React Redux -> TypeError: Object(...) is not a function - React Redux -> TypeError: Object(...) is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM