Skip to content
Advertisement

onClick of button triggering all the components to open – Reactjs

I implemented a Card component and basically generating a bunch of cards on some input data. I binded a setter function on button click on every card which basically expands and collapse it. Even after putting unique keys to the div is sort of triggering all the cards to open at once.

Here is the code piece:

JavaScript

Advertisement

Answer

Create a component that manages it’s own state and render that component.

JavaScript

then render it like

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement