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

123
Views
Función en React para verificar qué componente debe devolverse

Actualmente tengo el siguiente código:

 const renderModal = location.state?.modal ?? isModal ?? false; const FormComponent = renderModal ? FormModal : Default;

que verifica si renderAsModal es verdadero y luego devuelve el componente Modal si es así (si no, el componente predeterminado)

Pero ahora tengo otro modal posible, que puedo verificar así:

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

¿Cómo puedo actualizar mi asignación de FormComponent para verificar renderCustomModal también para que mi CustomModal pueda incluirse en los 3 componentes de React que se pueden devolver? Cualquier enlace útil / mejores prácticas sería realmente apreciado.

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

0

Aquí es donde generalmente divido mi lógica en una función separada.

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

entonces puedes simplemente:

 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!