Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

TypeError: todo.filter is not a function React Js

I'm creating a todo app and I ran across a issue im confused on how to fix. I get a TypeError: todo.filter is not a function when I click on the Icon button to remove to todo task. this is what I have in my code.

import React from 'react'
import Button from '@material-ui/core/Button';
import DeleteIcon from '@material-ui/icons/Delete';

function Todo({todo, setTodo}) {

    const removeHandler=()=>{

        setTodo(todo.filter((el) => el.id !== el.id))
        console.log(todo)
    }


    return (
        <>     
        <div className="list-container"> 
         <li className="todo-item" key={todo.id}>{todo.text}</li>

        <Button variant="contained" color="secondary" size="small">
        <DeleteIcon onClick={removeHandler}/>
        </Button>
        </div>
        </>


    )
}

export default Todo

also link to github if you need more detail.. thank you. https://github.com/mikefazek9/react-todo/tree/main/src