# React ToDo App: Done Button Is not Working

**URL:** <https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976>\
**Category:** General\
**Created:** [May 7, 2019, 4:45pm UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976 "2019-05-07T16:45:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivanilievski](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ivanilievski/32/39446_2.png) [@ivanilievski](https://forum.freecodecamp.org/u/ivanilievski)\
**Post date:** [May 7, 2019, 4:45pm UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/1 "2019-05-07T16:45:41Z")

</div>

I am currently making a ToDo App.  
The app is almost done but i want to make the green check box when clicked to change the style of that specific todo that is completed.

I have tried and the most i got was all elements to change style or none.

Here is the project:  
[https://codesandbox.io/s/z567lm8wp](https://codesandbox.io/s/z567lm8wp)

I also looked at nested state. But everyone i read says that nested state is over all bad design practice.

How do i make this button work?

---

<div class="post-metadata">

**Author:** ![shimphillip](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/shimphillip/32/158663_2.png) [@shimphillip](https://forum.freecodecamp.org/u/shimphillip)\
**Post date:** [May 7, 2019, 5:24pm UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/2 "2019-05-07T17:24:50Z")

</div>

What’s your done variable in your state?

What behavior are you expecting?

---

<div class="post-metadata">

**Author:** ![lekha](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lekha/32/106390_2.png) [@lekha](https://forum.freecodecamp.org/u/lekha)\
**Post date:** [May 7, 2019, 6:11pm UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/3 "2019-05-07T18:11:26Z")

</div>

There’s a lot of code refactoring that you could do here and also a lot of unnecessary logic imo. But for the problem at hand, the issue is from your `map` function on `line 40` in `App.js` – you never return the item again, so newStyledItems is `undefined`. Return is implied when you don’t have a block after the arrow function, but since you do, you have to specify it.

---

<div class="post-metadata">

**Author:** ![ivanilievski](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ivanilievski/32/39446_2.png) [@ivanilievski](https://forum.freecodecamp.org/u/ivanilievski)\
**Post date:** [May 7, 2019, 7:00pm UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/4 "2019-05-07T19:00:12Z")

</div>

When the green button is clicked the state is changed of done from false to true and when done is changed you can apply the style of completedStyle to that specific element that was clicked.

That was my initial reasoning behind done in state.  
I did that and all of the items and not just the one i clicked changed style.

---

<div class="post-metadata">

**Author:** ![ivanilievski](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ivanilievski/32/39446_2.png) [@ivanilievski](https://forum.freecodecamp.org/u/ivanilievski)\
**Post date:** [May 7, 2019, 7:10pm UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/5 "2019-05-07T19:10:27Z")

</div>

Ok but my issue is. How do i apply inline style to specific element on array of objects, that is in a child component (TodoItem.js) while i specify the style in parent component (App.js)

How do i properly select that item with click on a button in that item, and then give the item this design and then apply the design so the item will look differently from other items that are not completed?

---

<div class="post-metadata">

**Author:** ![lekha](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lekha/32/106390_2.png) [@lekha](https://forum.freecodecamp.org/u/lekha)\
**Post date:** [May 8, 2019, 6:25pm UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/6 "2019-05-08T18:25:47Z")

</div>

You can add a class to the item if the the item is `done`. So you’ve already added some CSS for this class, but now you have to toggle it if the item is `done`. This class applies to the `li` in `TodoItem.js`. So you can use string interpolation to add the class `done` to the `li` element when `item.done` is `true`.

---

<div class="post-metadata">

**Author:** ![ivanilievski](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ivanilievski/32/39446_2.png) [@ivanilievski](https://forum.freecodecamp.org/u/ivanilievski)\
**Post date:** [May 9, 2019, 8:44am UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/7 "2019-05-09T08:44:55Z")

</div>

I have Good News and Bad News.

God News is that i did. Bad News is that gave up the initial design to adapt to the new solution.

Instead of a Button Done, i used checkbox which have a property checked that returns true or false. that was really handy.

and i just use event to update the state of the done property.

Little bit of research did the job.

And when for that specific object done is true, you can do a little logic and change the design.

The design is similar to commercial todos. Is not as fancy but is good enough.  
I learned a lot with this app.

Thanks for your help.  
This is the final solution: [https://codesandbox.io/s/z567lm8wp](https://codesandbox.io/s/z567lm8wp)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 9:50am UTC](https://forum.freecodecamp.org/t/react-todo-app-done-button-is-not-working/275976/8 "2021-01-17T09:50:46Z")

</div>

Closed on January 17, 2021, 9:50am UTC


