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

181
Vistas
how to make state of component is not change if i use history.goBack() function

i have a boolean state and my code depend on that state one of them if the this state is true i will use history.goback()function , the second one come after the first condition i check if the state is false then do something , but what is happening now if the history.goback() ,the state boolean become false then the second condition hit . so how to fix it .

this my code


  const [isFormSubmitted, setIsFormSubmitted] = useState<boolean>(false);

  useEffect(() => {
    if (submitForm.status === RequestStatus.resolved) {
      setFormLoading(false);
      notification.success({
        message: t('messages.success'),
        description: t('messages.success.requestCreated'),
      });
      setIsFormSubmitted(true);
    } else if (submitForm.status === RequestStatus.rejected) {
      setFormLoading(false);
      notification.error({
        message: t('leaves.newRequest.message.leaveRequestError'),
        description: submitForm.error?.message?.includes('Leave request already exists')
          ? t('leaves.newRequest.error.alreadyExists')
          : submitForm.error?.message,
      });
    }
  }, [submitForm.status, t, submitForm.error?.message]);

useEffect(() => {
    if (isFormSubmitted) {
      history.goBack();
    }
  }, [history, isFormSubmitted]);

  const deleteProcessInstance = useCallback(async () => {


    if (isFormSubmitted === false && processInstanceIdRef.current) {


      try {
.......

}));
      } catch {
        notification.error({
          message: t('messages.error.wentWrong'),
          description: t('messages.error.tryAgainLater'),
        });
      }
    }
  }, [leaveRequestPDK, isFormSubmitted, dispatch, t]);


//this if the user leave the page then this useEffect hit 
 useEffect(
    () => () => {
      deleteProcessInstance();
    },
    // eslint-disable-next-line react-hooks/exhaustive-deps
    []
  );
about 4 years ago · Juan Pablo Isaza
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