Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Obtener indefinido no es un objeto cuando se usa FlatList de react-native

Recientemente comencé a estudiar React Native. Ahora trato de mostrar una matriz de objetos en la página. Hice todo como si estuviera bien, pero me sale un error:

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

Tengo dos preguntas, ¿qué estoy haciendo mal y por qué en React Native, los elementos se muestran usando FlatList y no a través del método del mapa? Aquí está mi fragmento de código:

 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 answers
Answer question

0

Tiene una key = {id} en su Text , y no hay una identificación definida en este punto. Y te falta el keyExtractor de FlatList . También en su renderItem , use item en lugar de task .

Prueba con esto:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!