I am making a todo list app with react.
I'm trying to adding todos to local storage but I'm stuck in the getItem part. I don't know where to put.
Right now, showing in local storage section but when I refresh the page it is not showing in todolist section.
function App() {
const [change, setChange] = useState();
const [todos, setTodos] = useState([]);
useEffect(() => {
console.log(todos);
});
const ChangeValue = (e) => {
setChange(e.target.value);
};
const AddTodo = (e) => {
const TodoId = Math.floor(Math.random() * 10000) + 1
const newTodo = { content: change, id: TodoId }
localStorage.setItem('todoInLocalStorage',change);
setTodos((oldTodos) => [...oldTodos, newTodo]);
e.preventDefault()
};
const DeleteButton = (id) => {
setTodos(todos.filter((item)=> item.id !== id));
};
const DeleteAll = () => {
setTodos([]);
};
return (
<div className="App">
<div className="frame">
<h1>To Do List</h1>
<FormInput ChangeValue={ChangeValue} AddTodo={AddTodo}/>
<div className="card-2">
<h2><u>To Do's</u></h2>
<div className="todos">
<Todos todos={todos} DeleteButton={DeleteButton}/>
</div>
</div>
<button onClick={DeleteAll} className="ClearTodo">
Clear All To Do
</button>
</div>
</div>
);
}