Skip to content

How to use the open function in useGallery hook? #704

Answered by MaximKondratev
mivd7 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello. I'm pretty sure what problem you have. Gallery component provides context for useGallery hook. If you call hook before rendering context, it won't find it. Probably how your code looks like:

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>
    );
}

Replies: 1 comment 1 reply

Comment options

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

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