Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda