我试图在代码中使用react select,但我一直遇到以下错误:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
我该怎么办?下面是要选择的链接https://react-select.com/home#animated-组成部分
import Select from 'react-select';
const options = [
{ value: '1', label: '1' },
{ value: '2', label: '2' },
{ value: '3', label: '3' },
{ value: '4', label: '4' },
{ value: '5', label: '5' },
{ value: '6', label: '6' },
{ value: '7', label: '7' },
{ value: '8', label: '8' },
{ value: '9', label: '9' },
]
function Sound() {
return (
<div className="Sound">
<Select options={options} />
</div>
);
}
export default Sound;
1条答案
按热度按时间jm2pwxwz1#
如果您共享的是整个代码,那么可能是因为您没有导入react。因此,它认为这是一个不接受钩子的javascript函数。