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

142
Views
No se puede actualizar el valor usando el reductor React JS después de hacer clic

Actualmente estoy aprendiendo useReducer y trato de convertir useState a useReducer en la aplicación de tareas pendientes. Mi problema :

  1. TOGGLE_TODO no puede actualizar el valor al hacer clic.
 case TOGGLE_TODO: let targetId = todoItem[action.index]; let newTodo = [...todoItem]; return (newTodo[targetId].completed = !newTodo[targetId].completed);
 <button value={index} onClick={(event) => dispatch({ type: TOGGLE_TODO, index: event.target.value, }) } > {todo.completed ? "done" : "pending"} </button>
  1. UPDATE_TODO, no tengo ni idea de cómo convertir esto a useReducer. ¿Puedo convertir esto también? Aquí está mi código usando useState.
 const onUpdate = (e) => { const target = e.currentTarget.value; const todoTarget = todoItem[target].name; setInput(todoTarget); setTodoIndex(target); };

Y aquí está mi codesandbox para el código completo. usando useState y usando useReducer

about 4 years ago · Juan Pablo Isaza
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!