drcmda / react-contextual

🚀 react-contextual is a small (less than 1KB) helper around React 16s new context api
MIT License
642 stars 23 forks source link

Warning: <Consumer> was rendered outside the context of its <Provider> #9

Closed JJLost closed 6 years ago

JJLost commented 6 years ago

These examples arent exactly a direct comparison but: Warning with Decorators No Warning with Components

I have scenarios in my application where certain contexts are optional.

Is this warning expected behavior? I would prefer to remove warnings before production.

drcmda commented 6 years ago

@JJLost They're from React/react-broadcast and until now expected. Curious if they're also in the upcoming release i updated your box to react@next and react-dom@next (1.6.4-alpha) then the warnings seem to disappear: https://codesandbox.io/s/3yplp3pqqm

It remains to be seen if they have them in the next release. Technically a consumer outside a provider doesn't make much sense, though. At most it could receive a default value, the one you can provide as second argument to the context creation hocs:

@namedContext(props => props.id, "hello world")
class ...

But that value is stale and a consumer won't receive updates when it's placed outside.