react-toggle icon indicating copy to clipboard operation
react-toggle copied to clipboard

How to use inside a loop

Open imar26 opened this issue 7 years ago • 1 comments

Hi,

I have an array and I want this toggle button for each element inside the array. How can I make it specific to each element? Currently, on one click, it makes changes to all the toggle buttons I have on the page. I want to make it specific. Any help is appreciated. Thanks!

imar26 avatar Apr 15 '18 23:04 imar26

@imar26 This has nothing to do with react-toggles and you probably have figured it out already but just for completeness:

The problem is most likely in your onChange function. You need to update just the one toggles that got clicked and not every toggle in the array. You can achieve this e.g. by passing an id into your onChange-handler (or any other field or combination of fields that are unique). See https://jsfiddle.net/triepm/n5u2wwjg/218256/ for a quick example.

triepm avatar Oct 19 '18 19:10 triepm