Tengo esta aplicación de tareas pendientes que hice con redux pero quiero usar el almacenamiento local, la cuestión es que no sé cómo usarla, investigué un poco pero obtuve muchos errores como "todos.map is not a function" ¿pueden ustedes? ¿ayúdame? el "todos" es una matriz de objetos para el estado inicial
PD: sin el almacenamiento local funciona bien
tienda.js
export const store = createStore( reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() );reductor.js
export const reducer = (state = todos, action) => { let newTodos; // eslint-disable-next-line default-case switch (action.type) { case ADD_TODO: newTodos = [...state]; newTodos.push(action.payload); return newTodos; case DELETE_TODO: newTodos = [...state]; newTodos = newTodos.filter((todo) => todo.id !== action.payload); return newTodos; case UPDATE_TODO: newTodos = [...state]; let index = -1; for (let i = 0; i < newTodos.length; i++) { index++; if (newTodos[i].id === action.payload.id) { break; } } if (index !== -1) { newTodos[index] = action.payload; return newTodos; } } return state; };TodoList.js
const TodoList = () => { const todos = useSelector((state) => state); return ( <div> {todos.map((todo) => { return <Todo key={todo.id} todo={todo} />; })} </div> ); }; export default TodoList;almacenamientolocal.js
export function loadState() { try { const serializedState = localStorage.getItem("state"); if (serializedState === null) { return undefined; } return JSON.parse(serializedState); } catch (error) { return undefined; } } export function saveState(state) { try { const serializedState = JSON.stringify(state); localStorage.setItem("state", serializedState); } catch (error) { alert(`Error while saving state: ${error.message}`); } }