-1
I’m having trouble getting this little piece of code to work:
Here is my code:
import React, {SetStateAction} from 'react';
import {BsCheck, BsTrashFill} from 'react-icons/bs';
type Props = {
text: string,
todos: SetStateAction<never[]>,
setTodos: React.Dispatch<React.SetStateAction<never[]>>
}
const Todo: React.FC<Props> = ({text, todos, setTodos}) => {
const deleteHandler = () => {
setTodos(todos.filter(el => el.id !== todos.id))
}
return(
<div className="todo">
<li className="todo-item">{text}</li>
<BsCheck className="check" size={35}/>
<BsTrashFill onClick={deleteHandler} className="trash" size={35}/>
</div>
);
}
export default Todo;
The mistakes are:
Property 'filter' does not exist on type 'Setstateaction<Never[]>'.
Property 'filter' does not exist on type '(prevState: Never[]) => Never[]'.Parameter 'el' implicitly has an 'any' type.
Property 'id' does not exist on type 'Setstateaction<Never[]>'.
Property 'id' does not exist on type 'Never[]'.
You know what the guy is
never
? It doesn’t make much sense to use it there...– Luiz Felipe
as commented by @Luizfelipe, since the type was used
never
, must not be dealing with a valid array, so thefilter
cannot be used– Ricardo Pontual