Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

useEffect not firing at all

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading