简体   繁体   English

我不断收到:错误:无效的挂钩调用。 Hooks 只能在函数组件内部调用

[英]I keep getting:Error: Invalid hook call. Hooks can only be called inside of the body of a function component

I've tried everything creating a separate function for a hook using npm link inside the react and the react-dom and even tried implementing hooks at different levels anyway here is the problem trying to use fuse I'm using visual studio enterprise我已经尝试了所有使用 react 和 react-dom 中的 npm link 为钩子创建单独函数的所有方法,甚至尝试在不同级别实现钩子无论如何这里是尝试使用保险丝的问题我正在使用 Visual Studio Enterprise

static renderForecastsTable(forecasts) {

        const [query, setQuery] = useState('');<-- problem line
        const fuse = new Fuse(forecasts, { keys: ['mjesto'] })
        const results = fuse.search(query);
        console.log(results);
        return (...)

        function handleOnSearch({ currentTarget = {} }) {
            const { value } = currentTarget;
            setQuery = value;

        }


    }

Hooks can only be called from functional components.钩子只能从功能组件中调用。 You could refactor your code into a functional component like...您可以将代码重构为功能组件,例如...

function ForecastsTable() {
  const [query, setQuery] = useState('');

  const handleOnSearch = () => {
    ...
  };

  return (
  );
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 反应,得到错误:无效的钩子调用。 Hooks 只能在函数组件的主体内部调用 - React, getting Error: Invalid hook call. Hooks can only be called inside of the body of a function component 为什么我在以下代码中收到此错误“反应无效的挂钩调用。只能在 function 组件的主体内部调用挂钩”? - Why am i getting this error "react Invalid hook call. Hooks can only be called inside of the body of a function component" in the following code? 反应钩子错误:无效的钩子调用。 钩子只能在 function 组件的主体内部调用 - React hook Error: Invalid hook call. Hooks can only be called inside of the body of a function component 收到此错误“无效的挂钩调用。 钩子只能在 function 组件的主体内部调用。” 在反应功能组件内? - Getting this error “Invalid hook call. Hooks can only be called inside of the body of a function component.” inside a react functional component? 导入异步 function 错误:挂钩调用无效。 钩子只能在 function 组件的内部调用 - Importing async function error: Invalid hook call. Hooks can only be called inside of the body of a function component 错误消息:未捕获错误:无效挂钩调用。 钩子只能在 function 组件的内部调用 - Error Message: Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component 错误。 错误:无效挂钩调用。 钩子只能在 function 组件的内部调用 - Error. Error: Invalid hook call. Hooks can only be called inside of the body of a function component 未捕获的错误:无效的挂钩调用。 钩子只能在函数组件的主体内部调用吗? - Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component? React 17:错误:无效的钩子调用。 钩子只能在 function 组件的主体内部调用 - React 17: Error: Invalid hook call. Hooks can only be called inside of the body of a function component React Native:错误:无效的挂钩调用。 钩子只能在 function 组件的主体内部调用 - React Native: Error: Invalid hook call. Hooks can only be called inside of the body of a function component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM