Last active
July 25, 2021 18:32
-
-
Save KevinVR/67de190051440f245c31cbfa1235fdc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState} from 'react'; | |
const LightBox = ({ children, src, alt, Wrapper = 'div' }) => { | |
const [isOpen, setIsOpen] = useState(false); | |
const toggleIsOpen = () => { | |
setIsOpen(!isOpen); | |
}; | |
return ( | |
<Wrapper onClick={toggleIsOpen}> | |
{children} | |
{isOpen ? | |
<div onClick={toggleIsOpen}> | |
<img src={src} alt={alt} /> | |
</div> | |
: null} | |
</Wrapper> | |
); | |
}; | |
export default LightBox; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment