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

101
Views
In React useEffect shoud l I return an inline function that calls another function or just the function itself

Basically my question is whether there is any runtime difference between the two ways I list below of returning a cleanup function from a useEffect call. Is there a common best practice? I didn't see anything about it in the reactjs docs so I'm curious if there is any advantage to either practice.

Specifically:

  • Is the call stack different aside from the extra anonymous function?

  • Are there circumstances where it might affect the this keyword?

  • Is one safer than the other?


import React, { useEffect } from 'react';

function aPlainJsFunction() {
    console.log("Bar");
}

Example = () => {
    useEffect(() => {
        console.log("Foo");
        return aPlainJsFunction; // **This Line**
    }
    return <Text>Example</Text>
}

-or-

import React, { useEffect } from 'react';

function aPlainJsFunction() {
    console.log("Bar");
}

Example = () => {
    useEffect(() => {
        console.log("Foo");
        return () => {          // **These Lines**
            aPlainJsFunction(); // **These Lines**
        }                       // **These Lines**
    }
    return <Text>Example</Text>
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Is the call stack different aside from the extra anonymous function?

No

Are there circumstances where it might affect the this keyword?

Unsure - would guess no

Is one safer than the other?

No

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!