• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: How to make only one button disabled on click in map method and how to change className after the timer expires in React?

Resolved: How to make only one button disabled on click in map method and how to change className after the timer expires in React?

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

How to make only one button disabled on click in map method? With the help of the disabled hook, I have all pressed buttons . And how to make it so that after the timer expires the ‘current__events__hot-price disabled’ className changes back to ‘current__events__hot-price’?

Answer:

From what I can gather, you toggle one element’s status by index and disable the button at that specific index. Instead of toggling the statusItem property (a state mutation, BTW) you should just store the index of the “active” item.
Add an activeIndex state that is null in its “inactive” state, and equal to an index when it is “active”. The useEffect hook should just instantiate the interval and the interval callback should just decrement the time left. Use a separate useEffect hook with a dependency on the timeLeft state to reset the activeIndex and timeLeft states. Disable the button element when the activeIndex equals the mapped index. Pass the activeIndex state to the CSS classname utility functions.
Example:

If you have better answer, please add a comment about this, thank you!

colors javascript react-hooks
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Unable to run Docker .NET 6 console image

02/04/2023

Resolved: Input Focus between two React Components

02/04/2023

Resolved: linq2db throws exception when filtering by nested collection

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.