I called a function setTodos from the parent in my child components, but this returns the following error:
setTodos is not a function
Can you explain me why this happened, thanks a lot. Here is my code:
import React, { useState } from 'react';
import './App.css';
import Form from './components/Form';
import TodoList from './components/TodoList';
function App() {
const [inputText, setInputText] = useState("");
const [todos, setTodos] = useState([]);
return (
<div className="App">
<header>
<h1>Phuc's Todo list</h1>
</header>
<Form inputText={inputText} todos={todos} setTodos={setTodos}/>
<TodoList/>
</div>
);
}
export default App;
import React from 'react';
const Form = ({inputText, setInputText, todos, setToDos}) => {
const inputTextHandler = (e) => {
setInputText(e.target.value);
}
const submitTodoHandler = (e) => {
e.preventDefault();
setToDos([
...todos,
{text: inputText, completed: false, id: Math.randowm()*1000}
])
}
return (
...
)
}