How to use the open function in useGallery hook? #704
-
Hi,
My code looks roughly like this where the button to open the gallery is outside the image items. However clicking on the button doesn't seem to do anything. I can't find an example in your docs or anywhere else on how to use this. Could you please explain or share a working example? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello. I'm pretty sure what problem you have. const App = () => {
const { open } = useGallery(); // will not work. there is no context rendered before App component
return (
<Gallery>
{your code here}
</Gallery>
)
} How it should look like: const AppContent = () => {
const { open } = useGallery(); // will work, context is rendered
return (
{your code}
)
}
const App = () => {
return (
<Gallery>
<AppContent />
</Galler>
);
} |
Beta Was this translation helpful? Give feedback.
Hello. I'm pretty sure what problem you have.
Gallery
component provides context foruseGallery
hook. If you call hook before rendering context, it won't find it. Probably how your code looks like:How it should look like: