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

158
Views
Updating the button type based on boolean value

I'm wondering is it possible to update the button type between "submit" & "button" based on a boolean value: form?.hasErrors)

Here's my code:

    const btnType = () => {
      if (form?.hasErrors) {
        return "submit";
      }
      return "button";
    };

    return (
      <>
          <StyledButton
            onClick={!form?.hasErrors() ? handleShowModal : undefined}
            type={btnType()}
          >
            Search
          </StyledButton>
   );

I basically just want to ensure that if the form has errors, that the button type is set to "submit" and if not, it will be set to "button" (default).

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

0

I don't know why you want this. But i think you can use this.

  <StyledButton
    onClick={!form?.hasErrors() ? handleShowModal : undefined}
    type={form?.hasErrors() ? "submit": "button"}
  >
    Search
  </StyledButton>
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!