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

101
Views
¿Cómo paso un accesorio a una hoja de estilo en React Native?

Tengo un accesorio llamado isProfile que es usado por un componente (Feed) que usa la hoja de estilo a continuación. Quiero representar condicionalmente la altura del contenedor en función de si la propiedad isProfile está configurada como verdadera o falsa.

 function Feed({isProfile}){ return( <View style={style.container}> </View> ) } const styles = StyleSheet.create({ container:{ backgroundColor:colors.primary, width:windowWidth, justifyContent:"center", height: isProfile ? windowHeight : windowHeight*0.87, },
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Así resolví mi problema.

Cambié mi código de hoja de estilo como tal

 const styles = (isProfile) => StyleSheet.create({ container:{ backgroundColor:colors.primary, width:windowWidth, justifyContent:"center", height: isProfile ? windowHeight : windowHeight*0.87, }, )}

Y luego pasé a prop a la styleSheet como tal

 <View style={styles(isProfile).container}> </View>
about 4 years ago · Juan Pablo Isaza Report

0

Debe cambiar los estilos a una función que acepte el parámetro:

 function Feed({isProfile}){ return( <View style={createStyles(isProfile).container}> </View> ) } const createStyles = (profile) => StyleSheet.create({ container:{ backgroundColor:colors.primary, width:windowWidth, justifyContent:"center", height: profile ? windowHeight : windowHeight*0.87, },

La variable isProfile (prop) es local para el componente e invisible en el exterior, por lo que debe pasarse como parámetro

about 4 years ago · Juan Pablo Isaza Report

0

Puede almacenar varios estilos usando una matriz de objetos para style style={[{},{}]} etc. Esto le permite agregar la segunda parte que agregué

 function Feed({isProfile}){ return( <View style={[style.container,{height: isProfile ? windowHeight : windowHeight*0.87,}]}> </View> ) } const styles = StyleSheet.create({ container:{ backgroundColor:colors.primary, width:windowWidth, justifyContent:"center", },
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!