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

138
Visualizações
useEffect not dispatching action in react/redux project

I am working on a React/Redux project and am attempting to remove a progress spinner that is getting stuck on my error page. I have confirmed my ClearAllSpinners action is working correctly, but I believe it is clearing the spinners prematurely, prior to the spinner showing up, since it is not working.

In my error page component, I have the following useEffect hook, which I have been trying to dispatch my action from anytime the page renders or there is a change to isAnySpinnerActive:

useEffect(() => {
  dispatch(ClearAllSpinners());
}, [dispatch, isAnySpinnerActive]);

I know the action clears the spinners as intended since the following function sets a spinner and then clears it after 5 seconds successfully (this function was used solely as a test):

const addSpinner = () => {
  dispatch(ShowSpinner('test-spinner'));
  setTimeout(() => {
    dispatch(ClearAllSpinners());
  }, 5000);
};

Is there any other way I can dispatch my action anytime the error page is rendered and then again after any spinners may possibly appear, other than the useEffect hook I am using?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you are using the useEffect hook which triggers to call after a variable or statement has changed or triggered by default as componnetDidMount. you can read more about that here.

these variables or states must be added as your dependencies array to useEffect work properly as your expectation.

you want to call your dispatch action in your useEffect, it's okay, but when?

your snippet tells that dispatch ClearAllSpinners when your component did mount!!

you can do this with your status variable(which controlling Spinner visibility) like this:

useEffect(() => {
    if(showSpinner) {
      // triggered when showSpinner is true
      setTimeout(() => {
         dispatch(ClearAllSpinners());
      }, 5000)
    } else {
      // triggered when your component did mount or when showSpinner was false!!
    }
}, [dispatch, showSpinner])
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