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

Lightbox only opens on second click #208

Open
brennooth opened this issue Mar 31, 2022 · 1 comment
Open

Lightbox only opens on second click #208

brennooth opened this issue Mar 31, 2022 · 1 comment

Comments

@brennooth
Copy link

I'm currently facing the issue that I have 8 buttons that open one and the same lightbox component with varying props.
The documentary states that props are not reactive and that the key prop should be used to unmount and remount the lightbox.
However, now I'm facing the issue that with an introduced key prop, I need two clicks for the lightbox to open and I simply can't figure out what i'm missing.

<FsLightbox
     toggler={this.state.toggler}
     sources={this.state.category.categoryA.map(o => o = <img src={o} />)}
     key={this.state.selectedCategory}
 />

The state of toggler and selectedCategory changes at the same time when clicking on each button.

When I'm not using the key prop, the lightbox opens on the first click, but later on crashes when the number of images to be displayed changes.
Any ideas what could be causing this? We're out of ideas since we think we're using this according to the provided documentation.
Thanks!

@akira108
Copy link

How do you invoke setToggler?
In my case with setToggler(!toggler) as shown in the document, Same issue happened.
We need to make sure to invert current state correctly by using first argument of the set function like setToggler(prev => !prev).

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