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

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

我已经尝试了所有使用 npm link 在 react 和 react-dom 中为钩子创建单独函数的所有方法,甚至尝试在不同级别实现钩子无论如何这是尝试的问题使用 fuse 我正在使用 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 只能从功能组件调用。您可以将代码重构为功能组件,例如...

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

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

  return (
  );
}