useDogProviderState will never throw because even if there is no DogDataProvider above the component, React.useContext(DogDataProviderContext) will return the default value initState
If anyone is interested, I rewrote the Flexible Compound Components example with functional components instead of classes: sandbox
Thank you for pointing this out. I have updated the article with changes to Provider Pattern and added examples for Compound Components and Flexible Compound Components with functional components.
Actually the purpose of useDogProviderState is to make sure that the consumer of the DogDataProviderContext will be under the DogDataProvider in the React tree in order to consume the value provided from the provider. They would not want something like: const App = () => <Profile /> :D
Actually there's a discussion about this on Twitter: twitter.com/kentcdodds/status/1125...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
useDogProviderState
will never throw because even if there is noDogDataProvider
above the component,React.useContext(DogDataProviderContext)
will return the default valueinitState
If anyone is interested, I rewrote the Flexible Compound Components example with functional components instead of classes: sandbox
Thank you for pointing this out. I have updated the article with changes to Provider Pattern and added examples for Compound Components and Flexible Compound Components with functional components.
Actually the purpose of
useDogProviderState
is to make sure that the consumer of theDogDataProviderContext
will be under theDogDataProvider
in the React tree in order to consume the value provided from the provider. They would not want something like:const App = () => <Profile />
:DActually there's a discussion about this on Twitter: twitter.com/kentcdodds/status/1125...