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

215
Views
failed to display array items and flags error: Uncaught TypeError: Cannot read properties of undefined (reading 'map')

i'm a newbee still flirting around reactjs. why do i get this error anytime i trying displaying the array content of tasks. this is my App.js

import React from 'react';
import { useState } from 'react'
import './index.css';
import Navbar from './components/layout/Navbar';
import Tasks from './components/Tasks';
// import Message from './components/Message';
// import FunctionClick from './components/FunctionClick';

const App = () => {
  const [tasks, setTasks] = useState([
    {
      id: 1,
      text: 'This is the first text',
      day: 'Feb 5th at 2:30pm',
      reminder: true,
    },
    {
      id: 2,
      text: 'Meeting at School',
      day: 'Feb 6th at 1:30pm',
      reminder: true,
    },
    {
      id: 3,
      text: 'third meeting',
      day: 'Feb 6th at 1:30pm',
      reminder: true,
    },
  ])
 
  return (
    <div className="container">
      <Navbar />
      <Tasks tasks={tasks}/>
    </div>
  
  );

}

export default App;

and this is my Tasks.js

import React from 'react'
import  Task  from './Task'

const Tasks = ({tasks}) => {
  
  return (
    <>
    {tasks.map((task) => (
    <Task key={task.id} task={task} />
    ))}
    </>
  )
}

export default Tasks

Task.js

import React from 'react'

export const Task = ({task}) => {
  return (
    <div className='task'>
        <h3>{task.text}
        </h3>
    </div>
  )
}

export default Task;

it doesn't show error in the console but shows in the browser. i've been stuck. help me please. you can try testing it on your app. thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think as per your error

Uncaught TypeError: Cannot read properties of undefined (reading 'map')

if you make changes as following

const Tasks = ({tasks}) => {
  if(tasks && tasks.length > 0) {
    return (
      <>
      {tasks.map((task) => (
        <Task key={task.id} task={task} />
       ))}
       </>
     )
    }
   else return null;
}

then you can skip that error, As you can see I put if condition inside Tasks component to check tasks array

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!