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

189
Views
Javascript: declaraciones if sobre devoluciones y vistas

Quiero consolidar estas declaraciones if para hacer esto lo más eficiente posible sin dejar de poder realizar el caso 1 solo, el caso 2 solo, el caso 1 y 2 juntos, y ni el caso 1 ni el caso 2. ¿Hay alguna manera de hacer esto? ?

 if(x >= 100 && y < 100){ return( <View> <Text> this is case 1 </Text> </View> )} if(x < 100 && y >= 100){ return( <View> <Text> this is case 2 </Text> </View> )} if(x < 100 && y < 100){ return( <View> <Text> this is case 1 </Text> </View> <View> <Text> this is case 2 </Text> </View> )} if(x >= && y >= 100){ return( <View> <Text> this is case 4 </Text> </View> )}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Pon tu valor de retorno en una variable que puedas concatenar para cada caso.

 retval = ''; if (y < 100) { retval += <View> <Text> this is case 1 </Text> </View> ; } if (x < 100) { retval += <View> <Text> this is case 2 </Text> </View> ; } if (retval == '') { // neither case return( <View> <Text> this is case 4 </Text> </View> ); } else { return retval; }
about 4 years ago · Juan Pablo Isaza Report

0

Puede recopilar las cadenas deseadas y devolver la colección formateada o el caso cuatro.

 const take = []; if (x < 100) take.push('this is case 2'); if (y < 100) take.push('this is case 1'); return take.length ? take.map(/* your formatting */) : 'this is case 4';
about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto:

 const el1 = ( <View> <Text> this is case 1 </Text> </View> ) const el2 = ( <View> <Text> this is case 2 </Text> </View> ) ... const conditions = { el1, el2, ... } if (x >= 100 && y < 100) return conditions.el1 else if (x < 100 && y >= 100) return conditions.el2 else if (x < 100 && y < 100) return conditions.el1 + conditions.el2 else return conditions.default || ''
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!