Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
'TypeError: props.todoList is undefined' in React

im creating a simple app using the FARM(Fast API,React, MongoDB). I was following a tutorial on YT(https://www.youtube.com/watch?v=OzUzrs8uJl8). Ive been trying to solve this problem for the last day but no luck, if anyone can help that would be greatly appreciated, thanks

Todo.js

import axios from "axios"
import React from "react"

function TodoItem(props) {
    const deleteTodoHandler = (title) => {
        axios.delete('http://localhost:8000/api/todo/${title}').then(res =>console.log(res.data))}
        return (
            <div>
                <p>
                    <span style={{ fontWeight: 'bold, underline'}}>{props.todo.title} : </span> {props.todo.description}
                    <button onClick={() => deleteTodoHandler(props.todo.title)}
                    className="btn btn-outline-danger my-2 mx-2" style= {{'borderRadius':'50px',}}>X</button>
                    <hr></hr>
                </p>
            </div>
        )
}

export default TodoItem;

TodoListView.js

import TodoItem from "./Todo"

 function TodoView(props) {
     return (

         <div>
             <ul>
                {props.todoList.map(todo => <TodoItem todo= 
                {todo} />)}
             </ul>
         </div>
     )
 }
export default TodoView

p.s. if its a syntax error im sorry

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The issue is here:

props.todoList

here todoList is coming from axios call and which is an async call and the data is not available on first render and you are trying to access some data which is not available that's why the error.

So use a conditional render like:

{
  ( props.todoList && props.todoList.length > 0 )
  ?
  props.todoList.map(todo => <TodoItem todo={todo} />)
  :
  null
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda