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

119
Views
Function in React to check which component should be returned

I currently have the following code:

const renderModal = location.state?.modal ?? isModal ?? false;

const FormComponent = renderModal ? FormModal : Default;

which checks if renderAsModal is true & then returns the Modal component if so (if not, default component)

But now I have another possible modal, which I can check for like so:

const renderCustomModal: boolean =
   location.state?.modal ?? isModal ?? form.key === "UniqueKey" ?? false;

How can I update my FormComponent assignment to check for renderCustomModal as well so my CustomModal can be included in the 3 React components that can be returned? Any helpful links/ best practises would be really appreciated.

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

0

This is where I generally break my logic out into a separate function.

const pickFormComponent = (arguments, you, need) {
    if (someCondition) return FormModal;
    if (someOtherCondition) return OtherComponent;
    return Default;
}

then you can just:

const FormComponent = pickFormComponent(and, some, arguments);
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!