I'm new to React. I thought it'll be fun to make a ToDoList Project but it ended up being a lot of work, and still, I can't figure out this error. firstFile-app.js this file contains the useEffect..in which I'm having issues
import React,{ useState, useEffect } from "react";
import './App.css';
//Importing Components
import Form from "./components/Form"
import TodoList from "./components/TodoList";
function App() {
// All of our states
const [inputText,setInputText] = useState("");
const [todos,setTodos] = useState([]);
const {status,setStatus} = useState("all");
const {filteredTodos,setFilteredTodos} = useState([]);
// Use Effect
useEffect(() => {
filterHandler();
}, [todos, status]);
// Functions
const filterHandler = () =>
{
switch (status)
{
case "completed":
setFilteredTodos(todos.filter((todo) => todo.completed === true));
break;
case "uncompleted":
setFilteredTodos(todos.filter((todo) => todo.completed === false));
break;
default:
setFilteredTodos(todos);
break;
}
};
return (
<div className="App">
<header>
<h1>Afraz's ToDo List</h1>
</header>
<Form
inputText={inputText}
todos={todos}
setTodos={setTodos}
setInputText={setInputText}
setStatus={setStatus}
/>
<TodoList
setTodos={setTodos}
todos={todos}
filteredTodos={filteredTodos}
/>
</div>
);
}
export default App;
secondFile-todolist.js this is the file in which I'm trying to use the function...to render the list
import React from "react";
// Import Components
import Todo from "./Todo";
const TodoList = ({ todos,setTodos,filteredTodos }) =>
{
console.log(filteredTodos);
return(
<div className="todo-container">
<ul className="todo-list">
{filteredTodos.map((todo) => (
<Todo
setTodos={setTodos}
todos={todos}
key={todo.id}
todo={todo}
text={todo.text}
/>
))}
</ul>
</div>
);
};
export default TodoList;
TypeError: Cannot read property 'map' of undefined.....How to fix it? i have no clue! as I said I'm new to react.