Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use inside a loop #123

Open
imar26 opened this issue Apr 15, 2018 · 1 comment
Open

How to use inside a loop #123

imar26 opened this issue Apr 15, 2018 · 1 comment

Comments

@imar26
Copy link

imar26 commented Apr 15, 2018

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!

@triepm
Copy link

triepm commented Oct 19, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants