Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda