У меня есть следующий компонент без сохранения состояния:
import React, {useState, useEffect} from 'react';
import ReactDOM from 'react-dom';
import {Button, Form, FormGroup, Label, Input, FormText} from 'reactstrap';
function Trend() {
const [state, setState] = useState({
dataTypes: []
});
return (
<Form>
<FormGroup>
<Input type="select" multiple>
{state.dataTypes.map(type => {
return <option>{type}</option>
})}
</Input>
</FormGroup>
</Form>
);
}
Однако, когда я пытаюсь его запустить, я получаю следующую ошибку:
react.development.js:88 Uncaught Invariant Violation: 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:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/warnings/invalid-hook-call-warning.html for tips about how to debug and fix this problem.
Однако ни один из нихВозможности верны, как вы можете видеть из приведенного выше кода и моей среды npm:
$ npm ls react
megaqc@1.0.0 /home/michael/Programming/MegaQC
└── react@16.8.6
$ npm ls react-dom
megaqc@1.0.0 /home/michael/Programming/MegaQC
└── react-dom@16.8.6
Что вызывает эту ошибку?