Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on build, state is undefined #1

Open
intelligence opened this issue Mar 18, 2020 · 1 comment
Open

Error on build, state is undefined #1

intelligence opened this issue Mar 18, 2020 · 1 comment

Comments

@intelligence
Copy link

Hello!

First and foremost, thanks for this resource!

I've implemented this in my app and it's been working great while in development, but now when I try to build my project I'm having some troubles.

  53 | 
  54 |   return (
> 55 |     <Menu state={state} menuNavigation={state.menuNavigation}>
     |                                               ^
  56 |       <Inner>
  57 |         <MenuLocal />
  58 |         <MenuGlobal />


  WebpackError: TypeError: Cannot read property 'menuNavigation' of undefined

Any idea for a fix?

@intelligence
Copy link
Author

Ok, so seems like passing initialState with usage of context is a quick and dirty fix
const state = useContext(GlobalStateContext) || { menuNavigation: 'closed' }

As per: gatsbyjs/gatsby#12104 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant