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

166
Vistas
Pass Custom Relative Image source to Image Tag React Native

I am trying to create a custom component in React Native which contains an Image tag with a custom source to be passed to it. The problem now is, I am getting an error that says Invalid call at line 17: require(imageSrc).

This is my GoalButton component code below:

const GoalButton = ({
  buttonStyle,
  onPress,
  text,
  imageSrc,
  imageStyle,
  textStyle,
}) => {
  return (
    <TouchableOpacity onPress={onPress}>
      <View style={buttonStyle}>
        <Image style={imageStyle} source={require(imageSrc)} />
        // Above line is Line 17
        <Text style={textStyle}>{text}</Text>
      </View>
    </TouchableOpacity>
  );
};

GoalButton.defaultProps = {
  buttonStyle: styles.buttonStyle,
  onPress: () => null,
  imageStyle: styles.imageStyle,
  textStyle: styles.textStyle,
};

export default GoalButton;

And I call it from outside like this:

<GoalButton text={'Meal Plan'} imageSrc={'../assets/images/plate.png'} />;

My question is, is there a way I can pass a relative image URL to the component and access it without any error like I was using it directly on the Image component.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

it is not possible, you can looked this,

https://stackoverflow.com/questions/30854232/react-native-image-require-module-using-dynamic-names#:~:text=The%20only%20allowed%20way%20to%20refer%20to%20an%20image%20in%20the%20bundle%20is%20to%20literally%20write%20require(%27image!name-of-the-asset%27)%20in%20the%20source.

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