Skip to content

React - Separating DOM and Data #2059

Answered by dimsemenov
BoBberAdmin asked this question in Q&A
Discussion options

You must be logged in to vote

Your case is specifically described at #separate-dom-and-data. All you gotta do is pass the array of all images to the lightbox during the initialization and call loadAndOpen with the corresponding index onclick.

Something like (haven't tested):

import React, { useEffect } from 'react';
import PhotoSwipeLightbox from 'photoswipe/lightbox';
import 'photoswipe/style.css';

const images = [
  {
    src: 'https://dummyimage.com/1500x1000/555/fff/?text=Image+1',
    width: 1500,
    height: 1000,
  },
  {
    src: 'https://dummyimage.com/1500x1000/555/fff/?text=Image+2',
    width: 1500,
    height: 1000,
  },
  {
    src: 'https://dummyimage.com/1500x1000/555/fff/?text=Image+3',
    width: 1500,

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@BoBberAdmin
Comment options

Answer selected by BoBberAdmin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants