I am facing problem using Simple React Lightbox Next js?

Lary John

I am building nextjs application. I want a lightbox feature that only show a button, then when I click the button it show the lightbox gallery. But default or on page load there should not be show images. Just when I click a button it show light box. Like when I clicked the button-

enter image description here

Then It start lightbox-

enter image description here

How can I do that?

Here I am trying to use Simple React LightBox. This package support hook. But there are not well documented to understand how to use hook. First Of all I create a button and then I create a lightbox component. Like this-

import {Container, Flex, Box, Image, Paragraph} from "theme-ui";
import SingleRooms from "data/SingleRooms";
import SimpleReactLightbox, {SRLWrapper, useLightbox} from "simple-react-lightbox";

const SingleImages = () => {
    const {openLightbox, closeLightbox} = useLightbox()
    return (
        <Container>
            <button onClick={() => openLightbox()}>
                Open the third image
            </button>
            <SimpleReactLightbox>
                <SRLWrapper>
                    <a href={SingleRooms.images[0].path}>
                        <img src={SingleRooms.images[0].path} alt="Umbrella"/>
                    </a>
                    <a href={SingleRooms.images[1].path}>
                        <img src={SingleRooms.images[1].path} alt="Blue sky"/>
                    </a>
                </SRLWrapper>
            </SimpleReactLightbox>
        </Container>
    );
};

export default SingleImages;

It is not working. Actually I don't know to use it. Please help me to use it with my wanted options. Just show a button then when clicked button there should be show the light box. Please help me.

novonimo

According to the simple-react-lightbox documentation:

First of all you need to wrap your React app with the main component so that it can create the context.

So in your top-level (root/main/index) component:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import SimpleReactLightbox from 'simple-react-lightbox'

ReactDOM.render(
  <React.StrictMode>
    <SimpleReactLightbox>  // ----> here
      <App />
    </SimpleReactLightbox> 
  </React.StrictMode>,
  document.getElementById("root")
);

export default App;

Now, in the SingleImages component:

import {Container, Flex, Box, Image, Paragraph} from "theme-ui";
import SingleRooms from "data/SingleRooms";
import {SRLWrapper, useLightbox} from "simple-react-lightbox";

const SingleImages = () => {
    const {openLightbox, closeLightbox} = useLightbox()
    return (
        <Container>
            <button onClick={() => openLightbox()}>
                Open the third image
            </button>
                <SRLWrapper>
                    <a href={SingleRooms.images[0].path}>
                        <img src={SingleRooms.images[0].path} alt="Umbrella"/>
                    </a>
                    <a href={SingleRooms.images[1].path}>
                        <img src={SingleRooms.images[1].path} alt="Blue sky"/>
                    </a>
                </SRLWrapper>
        </Container>
    );
};

export default SingleImages;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am facing a problem in Pagination using states in React JS

i am facing a problem regarding async storage in react native

I am facing problem in linked list in python

I am facing a problem in JavaScript/ReactJS

I am facing problem bootstrap table responsive

Why I am facing the condition problem in C?

I am facing problem to execute foreach loop

I am facing problem in creating a Graph implementation

I am facing a problem when I update data to mysql using jquery

I am facing problem while fetching data from database using prepared statement

I have a problem with two .js files in a react app! I am using the react-router-dom. My problem is with the Link tag

i am using open CV and i am facing this error

A simple situtation I am facing on sending a char as an instruction

Macro to transfer data from Access to Excel I am facing problem

I am facing problem in npm install express --save

How to solve this INFINITE LOOP problem in C program I am facing?

Is there a way to solve the problem I am facing after upgrading firebase in flutter

I am facing a problem regarding limiting my rows

I am facing little problem with lists and dicts in python

Am I facing overflow?

I am trying to get battery power status of my laptop using python, but facing problem with getting the live updated battery status value

I am trying to accessing the object through React facing error

How can I specify authentication globally instead of defining on every page in Next js, I am using next-auth package with react query

I am trying to make a discord chatbot but I am facing a problem(solved)

I am facing problems displaying audio file using python

why am I not able to show the data I am fetching from graphcms using next.js?

Why am I not seeing route attributes on my simple Next.js route?

I am facing this issue when I am running react-native run-android

Problem with API Routes not working in next js, (keep getting 404 not found) [I am new]