DEV Community

Discussion on: Creating a Toggle button in React

Collapse
 
link2twenty profile image
Andrew Bone

Very well sussed out 🙂. If I could suggest a one things that might make things easier for you.

As we're dealing with a toggle rather than storing you text in a state you could store a Boolean. Doing this make our inverting logic a lot simpler it also means we can do other things with with the state (like change the button colour).

Collapse
 
atbrakhi profile image
Rakhi

thank you for the suggestion. You are right, we can do that.

When I decided to write this blog, my main motive was to only focus on one functionality and explain end to end process of solving the problem, I would agree, if anyone if looking for more flexibility in their code base, your advice is very useful.