Reputation: 31
I am trying to make us of useEffect in my React component but I am encountering an issue with the following error:
TypeError: react_1.useEffect is not a function
and
Uncaught (in promise) TypeError: react_1.useState is not a function
I have imported the libraries like this
import React, { useEffect } from 'react'
and have the useEffect like this:
useEffect(() => {
console.log("This is cool")
}, [intentButton])
The react version is 16.7.0
Upvotes: 1
Views: 845
Reputation: 1799
this is because the react V16.7 does not have hooks
The resolution is to downgrade to
npm i react@next react-dom@next
which as of 2018/12/20 is 16.7.0-alpha.2:
yarn add react@next react-dom@next
then lose the test renderer:
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
it('renders without crashing', () => {
const div = document.createElement('div')
ReactDOM.render(<App />, div)
ReactDOM.unmountComponentAtNode(div)
})
This is what package.json
should be:
"react": "^16.7.0-alpha.2",
"react-dom": "^16.7.0-alpha.2",
Upvotes: 1