Skip to content

Nearly identical code producing different results. #2

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>
    );
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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