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

123
Visualizações
Getting undefined is not an object when using react-native's FlatList

Recently began to study React Native. Now I try to display an array of objects on the page. I did everything as if right, but I get an error:

Undefined is not an object (evaluating 'task.name'

I have two questions, what am I doing wrong and why in React Native, elements are displayed using FlatList and not via the map method? Here is my code snippet:

import React, {useState} from "react";
import {FlatList, StyleSheet, Text, View} from "react-native";

export default function Tasks() {

const [tasks, setTasks] = useState([
    {id: 1, name: "By Bread"},
    {id: 2, name: "By pizza"},
    {id: 3, name: "By snack"}
])

return (<View>
    <FlatList data={tasks} renderItem={({task}) => (
        <Text key={id}>{task.name}</Text>
    )}/>
        </View>)
}

const styles = StyleSheet.create({})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have a key = {id} in your Text, and there is no id defined at this point. And you are missing the keyExtractor of FlatList. Also in your renderItem, use item instead of task.

Try with this :

import React, {useState} from "react";
import {FlatList, StyleSheet, Text, View} from "react-native";

export default function Tasks() {

const [tasks, setTasks] = useState([
    {id: 1, name: "By Bread"},
    {id: 2, name: "By pizza"},
    {id: 3, name: "By snack"}
])

return (
    <View>
      <FlatList data={tasks} 
        renderItem={({item}) => (<Text keyExtractor={item => item.id}>{item.name}</Text>)}
      />
    </View>
    )
}

const styles = StyleSheet.create({})
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