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