-4
These are my mistakes:
Property 'todos' is Missing in type '{ setTodos: (todos: Itodo[]) => void; key: string; text: string; }' but required in type 'Props'.
Property 'id' does not exist on type 'Itodo[]'.
Type 'Dispatch<Setstateaction<Never[]>>' is not Assignable to type '(all: Itodo[]) => void'. Types of Parameters 'value' and 'todos' are incompatible.
Type 'ITodo[]' is not assignable to type 'SetStateAction<never[]>'. Type 'ITodo[]' is not assignable to type 'never[]'. Type
'Itodo' is not Assignable to type 'Never'.
Here’s the code:
import React from 'react';
import {BsCheck, BsTrashFill} from 'react-icons/bs';
interface ITodo {
id: string,
text: string,
completed: boolean
}
type Props = {
text: string,
todos: ITodo[],
setTodos: (todos: ITodo[]) => void
}
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;
import React from 'react';
import Todo from './Todo';
interface ITodo {
id: string,
text: string,
completed: boolean
}
type Props = {
todos: ITodo[],
setTodos: (todos: ITodo[]) => void
}
const TodoList: React.FC<Props> = ({todos, setTodos}) => {
return(
<div className="todo-container">
<ul className="todo-list">
{todos.map(todo => (
<Todo setTodos={setTodos} key={todo.id} text={todo.text}/>
))}
</ul>
</div>
);
};
import React, { useState } from 'react';
import './App.css';
import Form from './components/Form';
import TodoList from './components/TodoList';
function App(){
const [todos, setTodos] = useState([]);
const [inputText, setInputText] = useState("");
return (
<main>
<div className="title">
<h1><span suppressContentEditableWarning={true} contentEditable="true">Your name</span> todo list</h1>
</div>
<Form setInputText={setInputText} todos={todos} setTodos={setTodos} inputText={inputText}/>
<TodoList setTodos={setTodos} todos={todos}/>
</main>
);
}
export default App;
import React from 'react';
import { BsPlusSquareFill } from 'react-icons/bs';
import { v4 as uuidv4 } from 'uuid';
type Props = {
setInputText: (value: string) => void,
inputText: string,
todos: string[],
setTodos: (value: string[] | any) => any
}
const Form: React.FC<Props> = ({ setInputText, todos, setTodos, inputText }) => {
const getInputText = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputText(e.target.value);
}
const submitTodoHandler = (e: any) => {
e.preventDefault();
setTodos([
...todos, {text: inputText, completed: false, id:uuidv4()}
]);
setInputText("");
}
return(
<form>
<div className="row">
<div className="inputTodo">
<input value={inputText} type="text" placeholder="Write here your todo" onChange={getInputText}/>
< BsPlusSquareFill className="plus-sign" onClick={submitTodoHandler} size={40}/>
</div>
<select name="todos" id="todos">
<option value="all">All</option>
<option value="completed">Completed</option>
<option value="Uncompleted">Uncompleted</option>
</select>
</div>
</form>
)
}
export default Form;
How can I fix these mistakes?
I think I’ve seen a similar question these days, but the message is very clear
Type 'ITodo[]' is not assignable to type 'never[]'
is trying to use a type where is expectednever
, I mean, "nothing" so to speak– Ricardo Pontual
So how can I change the type? Why can’t I use Never
– Inês Barata Feio Borges
Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativations worth reading What is the Stack Overflow and the Stack Overflow Survival Guide (summarized) in Portuguese.
– Bacco