Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!