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

278
Visualizações
Javascript || React Native how to use map()
import React from "react";
import { View, Text, StyleSheet, ScrollView, Image } from "react-native";

const Icons = [
  { name: "Food", uri: require("./images/Food.png") },
  { name: "Mart", uri: require("./images/mart.png") },
  { name: "Car",  uri: require("./images/car.png")  }
];

const IconSelection = Icons.map((icons) => (
  <View>
    <Image source={icons.uri} />
    <Text style={{ textAlign: "center" }}>{icons.name}</Text>
  </View>
));

const styles = StyleSheet.create({});

export default IconSelection;

Is my way of adding images to my const Icons correct? Basically I want to create like a list of Icons using images and able to call them. Previously my method is basically handcode them but I found it is very messy. I think maps() could help me but I'm not really sure how to use it too. Thank you.

import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import IconSelection from "./icons";

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <IconSelection />
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

It says Check the render method of app. The error source is pointing require().

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

0

You are returning an array of items.

You most likely need a new component that wraps your icons. Something like this

const IconSelection = () => {
 return <>
   Icons.map((icons) => (
    <View>
     <Image source={icons.uri} />
     <Text style={{ textAlign: "center" }}>{icons.name}</Text>
    </View>
  )
 </>
}

You also need to make sure that the paths to images are correct and you have proper loaders for that file type.

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