Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
UseCallback in combination with StrictMode

I have the following code snippet in use while wrapping my whole React application with <React.StrictMode>.

function Quiz() {

    const fetchData = useCallback(
        async () => {
            console.log("hiho");
        },
        []
    );

    useEffect(() => {
        fetchData();
    }, [fetchData])

    return (
        <>
        </>
    )
}

For the initial load of my application fetchData is being called twice within my useEffect(). I am a bit puzzled as I assumed that useCallback() would prevent this (even though StrictMode calls the rendering twice).

Should I be worried that fetchData get's called twice? In my case fetchData returns random data which then has the side effect that the data changes during the render process on dev.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try removing the fetchData from the useEffect dependency array. I believe that should render it just once.

function Quiz() {
    const fetchData = useCallback(
        async () => {
            console.log("hiho");
        },
        []
    );

    useEffect(() => {
        fetchData();
    }, [])

    return (
        <>
        </>
    )
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!