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

134
Views
OnClick calls a function once

I have a button that is expected to call a function onClick. The function is being passed in as a prop. And this is what it looks like:

onClick={() => handleError && handleError()}

The problem here is that when I click on it, it only gets called once and doesn't get called again after that.

This is the handleError function, but the problem isn't the content of the function. It is that the function isn't being called at all after it has been called once:

  const handleError = (nextBtn: BtnItem) => {
    if (title === '') {
      setError(true);
    } else {
      if (nextBtn?.onClick) {
        nextBtn.onClick();
        console.log('clicked too');
      } else if (nextBtn?.route) {
        history.push(nextBtn.route);
        console.log('clicked');
      }
    }
  };

Any ideas why this might be happening? Any help will be appreciated. Thank you!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

onClick={handleError ? () => handleError() : () => {}}
about 4 years ago · Juan Pablo Isaza Report

0

Whats handleError? We need a bit more code to work with.

If you only want to execute the function if a variable is true. You can check it directly in the method you call and not in the onClick() itself.

Just do onClick={handleError}

about 4 years ago · Juan Pablo Isaza 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!