Skip to content

Instantly share code, notes, and snippets.

@KevinVR
Last active July 25, 2021 18:32
Show Gist options
  • Save KevinVR/76284bd5066001882b280f60e07ef14e to your computer and use it in GitHub Desktop.
Save KevinVR/76284bd5066001882b280f60e07ef14e to your computer and use it in GitHub Desktop.
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>
<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