Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
El almacenamiento local de React Redux para la aplicación de tareas pendientes no funciona

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}`); } }
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!