My useEffect is not firing at all:
import React, { useEffect } from 'react'
function Home(props) {
useEffect = (() => {
onPageLoad()
}, [])
const onPageLoad = () => {
console.log('hello from page load')
}
return (
<p>Home Component</p>
)
}
export default Home
I’m stumped on this. There’s nothing in the console.
>Solution :
There should be something some error at least in the developer console in the browser, since it seems you have written a syntax error. You are currently trying to assign a new value to the imported variable useEffect but I believe you may have meant to call the function instead:
import React, { useEffect } from 'react'
function Home(props) {
useEffect(() => {
onPageLoad()
}, [])
const onPageLoad = () => {
console.log('hello from page load')
}
return (
<p>Home Component</p>
)
}
export default Home