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 message unclear #2

Open
veroo-m opened this issue May 13, 2019 · 1 comment
Open

Error message unclear #2

veroo-m opened this issue May 13, 2019 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@veroo-m
Copy link

veroo-m commented May 13, 2019

const { container } = render(
  <div>
    <someLayeredComponent {...defaultProps} />
  </div>,
)

While rendering this element I would get this error

'Error: Uncaught [TypeError: Cannot read property 'host' of undefined]' 
' console.error node_modules/react-dom/cjs/react-dom.development.js:17117
    The above error occurred in the <Context.Consumer> component:
        in Layer (created by Modal)
        in Modal
    
    Consider adding an error boundary to your tree to customize error handling behavior.
    Visit https://fb.me/react-error-boundaries to learn more about error boundaries.'

The error logged in unclear as it doesn't specify that the error comes from the usage if this library, nor it's mentioned that the component should be rendered as:

const { container } = render(
  <LayersManager>
    <someLayeredComponent  {...defaultProps} />
  </LayersManager>,
)
@giuseppeg
Copy link
Owner

giuseppeg commented May 13, 2019

Yeah this is because you are using a consumer (Layer) without a provider (LayersManager) and so the consumer cannot destructure its value (which in this case is undefined)

<Consumer>
{({ host, root }) =>

Right now I create a single version of the library and don't make distinction between production and development, so I can't add a dev only warning. Maybe we can add the check all the time.

I will leave this issue open and see if the issue comes up again and in case add the fix above.

Thank you Veronica for reporting this!

@giuseppeg giuseppeg added enhancement New feature or request good first issue Good for newcomers labels May 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants