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

101
Visualizações
how to use image source in another file different from the file contains the image?

i am trying to use an image source with require function or uri in react native but the source will be use in calling the function that has the image, it doesn't work with me.

this is the image the contains the structure of the project and the image folder. enter image description here

this is the card file code:

import { View, Image, StyleSheet } from "react-native";
import colors from "../config/colors";
import React from "react";
import BookStoreText from "./BookStoreText";

function Card(title,subtitile,image) {
    return (
      <View style={styles.card}>
        <Image source={image} />
        <BookStoreText>{title}</BookStoreText>
        <BookStoreText>{subtitile}</BookStoreText>
      </View>
    );
}
const styles = StyleSheet.create({
    card:{
        borderRadius:15,
        backgroundColor:colors.white,
        marginBottom:20,
    }
})

export default Card;

this is the app.js source code:

//import WelcomeScreen from "./app/screens/WelcomeScreen";
//import colors from "./app/config/colors";
//import ViewImageScreen from "./app/screens/ViewImageScreen";
//import { MaterialCommunityIcons } from "@expo/vector-icons";
//import AppButton from "./app/components/AppButton";
import { View } from "react-native";
import React from "react";
import Card from "./app/components/Card";
function App() {
  return (
    <View
      style={{
        padding: 20,
        paddingTop: 100,
        backgroundColor: "#f8f4f4",
      }}
    >
      <Card
        image={require("./app/assets/chair.jpg")}
      ></Card>
    </View>
  );
}
export default App;

what i tried: i tried to use uri with the image istead of using require function but it doesn't work

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you need to destructure the image property in the Appcard component's params like this:

//notice the curly braces here
    function Card({title,subtitile,image}) {
        return (
          <View style={styles.card}>
            <Image source={image} />
            <BookStoreText>{title}</BookStoreText>
            <BookStoreText>{subtitile}</BookStoreText>
          </View>
        );
    }
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