Skip to content

Nearly identical code producing different results. #2

@dababygaming

Description

@dababygaming

I've been following your react tutorial and I've spent over an hour trying to figure out why my code doesn't work but the code I copied from your repo does. When I use my code, I am unable to delete items from the todo list; it produces an error saying deleteTodo is undefined in the console. But when I run the code from the repo, it works perfectly fine. I ran it through diffchecker.com and I was unable to find any differences between both pieces of code except for some spacing and semi-colons. Anyone able to help me out I feel like I'm going crazy.

Code below is from my TodoList.jsx file.

import { TodoItem } from "./TodoItem"

// doesn't work
// export function TodoList({ todos, toggleTodo, deleteTodo }) {
//     return (
//         <ul className="list">
//             {todos.length === 0 && "No Todos"}
//             {todos.map(todo => {
//                 return (
//                     <TodoItem 
//                         {...todo} 
//                         key={todo.id} 
//                         toggleTodo={toggleTodo} 
//                         deleteTode={deleteTodo} 
//                     />
//                 )
//             })}
//       </ul>
//     )
// }

// // copied from repo
export function TodoList({ todos, toggleTodo, deleteTodo }) {
    return (
        <ul className="list">
            {todos.length === 0 && "No Todos"}
            {todos.map(todo => {
                return (
                    <TodoItem
                        {...todo}
                        key={todo.id}
                        toggleTodo={toggleTodo}
                        deleteTodo={deleteTodo}
                    />
                );
            })}
        </ul>
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions