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

113
Views
Changing value to true onClick on object in react redux

I have a simple todo app in which i add my "todos" and if they are done i just simply click done. Although after clicking the state is updated and the payload is being printed to the console with proper actions "TODO_DONE", done field still remains false. my case for "TODO_DONE" in Reducer:

 case "TODO_DONE":
      return state.map((todo) => {
        if (todo.id === action.payload) {
          return {
            ...todo,
            done: true,
          };
        }
        return todo;
      });

i use it here:

<button onClick={() => doneTodo(todo)}>Done</button>

in the TodoList component:

import { deleteTodoAction, doneTodo } from "../actions/TodoActions";

import { connect } from "react-redux";
const TodoList = ({ todoss, deleteTodoAction, doneTodo }, props) => {
  return (
    <div>
      <h3>Director list</h3>
      {todoss.map((todo) => {
        return (
          <div>
            <div> {todo.name} </div>
            <button onClick={() => deleteTodoAction(todo)}>Usuń</button>
            <button onClick={() => doneTodo(todo)}>Done</button>
          </div>
        );
      })}
    </div>
  );
};

const mapStateToProps = (state) => {
  return {
    todoss: state.todoss,
  };
};

const mapDispatchToProps = {
  deleteTodoAction,
  doneTodo,
};

export default connect(mapStateToProps, mapDispatchToProps)(TodoList);

Ofc, the "done" value is my initial value inside TodoForm with Formik:

<Formik
        initialValues={{
          id: uuidv4(),
          name: "",
          date: "",
          done: false,
        }}
        onSubmit={(values) => handleSubmit(values)}
        enableReinitialize={true}
      >

Anyone knows why this doest not work?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Check your doneTodo action. Since you are passing todo object to it. It should be action.payload.id instead of action.payload.

todo.id === action.payload.id
about 4 years ago · Juan Pablo Isaza Report
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!