What's up ?
I'm trying to reproduce the sliding button effect from frontity home page with ReactJS (NextJS). Sliding buttons from Frontity
I managed to create the sliding button effect BUT I'm struggling with state management. I have all my objects mapped with a "isActive : true/false" element and I would to create a function that put "isActive : true" on the clicked button BUT put "isActive: false" on all the other buttons. I don't know the syntax / method for that kind of stuff.
Please, take a look at my codesandbox for more clarity (using react hooks): https://codesandbox.io/s/busy-shirley-lgx96
Thank you very much people :)
UPDATE: As pointed out above by Drew Reese, even more cleaner/easier is to have just one activeIndex state:
I have made a slight modification of your TabButtons:
When we click on a button, we set its isActive state to true and all the rest buttons to isActive: false. We also should use state, since we also declared it. Changing state will force component to re-render, also we are not mutating anything, but recreating state for buttons.