Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
¿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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda