I am trying to export a normal functional component using the react hooks but I am getting this error.
TypeError: Object(...) is not a function
when I remove the hooks and export it without any states it works. Exporting the same code as a Class component also works.
import React,{ useState } from 'react';
const Mycomponent = () => {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
export default Mycomponent;
here is how I am importing and using functional component.
import Mycomponent from './mycomponet';
class MYClassComponent extends Component {
render() {
return (
<Mycomponent />
}
}
I am using react 16.6.3
and used create-react-app
.
useState
is in fact a function? What version (and distribution file) of React are you using?16.6
and usedcreat-react-app