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

113
Vistas
disable button depending up response from redux

I currently show modals depending upon the updateReminderResponse object.

At the moment, you can click the submit button multiple times.

How can I disabled the button when the button is clicked, until UpdateVehicleReminder and saveNotifications have resolved, and aswell as updateReminderResponses as defined:

const [disabled, setDisabled] = useState(false);

const onSubmit = async () => {
  const success = await tryBiometrics();
  if (success) {
    setdisabled(true);
    ...
 
    tagNotifications(state);
    dispatch(
      UpdateVehicleReminder(
        ...
      )
    );
    try {
      await saveNotifications(state.notificationList);
    } catch (e) {
      logger.error("Error saving notifications", e);
      throw e;
    }
  }

  setdisabled(false);
};

const disableSubmit =
  disabled && typeof updateReminderResponses !== "undefined" ? true : false;

<Button
  title="example"
  buttonStyle={[buttons.primary]}
  titleStyle={buttons.primaryTitle}
  onPress={() => onSubmit()}
  disabled={disableSubmit} // disable until updateReminderResponse is defined
/>;
{
  updateReminderResponse && updateReminderResponse.updateFailure && (
    <MessageModals showModal callback={closeFailModal} />
  );
}
{
  updateReminderResponse && updateReminderResponse.success && (
    <MessageModals
      showModal
      successTick
      modalBody={myVehiclesCmsContent.updateRemindersSuccessMessage}
      callback={closeSuccessModal}
    />
  );
}
 
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Don't track the disabled condition in the state. It only depends on the value of updateReminderResponses.

Just test that variable.

<Button ... disabled={typeof updateReminderResponses === 'undefined'}
about 4 years ago · Santiago Trujillo Denunciar

0

You can use a ref to keep the button pressed state. It won't disable the button but can control submitting multiple times.

Make sure to set the pressed ref to false when you needed.

const pressed = useRef(false);



const onSubmit = async () => {
  if(!pressed.current){
     pressed.current = true
     // your code
  }
};
about 4 years ago · Santiago Trujillo 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