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

228
Visualizações
'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 Respostas
Responde à pergunta

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 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