I have the following stateless component in react:
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>
);
}
However, whenever I try to run it, I get the following error:
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.
However, none of these possibilities are correct, as you can see from the code above, and my npm environment:
$ 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
What is causing this error?