Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda