React Context Wrong Consumer Value
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior? Context provider contains the correct value but in the consumer I have the default value :
(value = bddf, the correct)
(value = cdn, wrong value)
Steps to reproduce I want to make a library that dynamically load the theme. I used create context.
I create a simple API for this : https://github.com/helabenkhalfallah/react-sg-components/tree/master/packages/sg-ui-core/src
I imported this lib as dependencies on my components : https://github.com/helabenkhalfallah/react-sg-components/blob/master/packages/sg-button/src/lib/SGButton.jsx#L3
And inside storybook : https://github.com/helabenkhalfallah/react-sg-components/blob/master/packages/storybook/stories/sg-button/SGButtonStory.jsx#L3
However inside context I get always the default value. When I inspect inside the provider I have the correct value but inside consumer I have the default value.
I tried also hooks but the same issue.
The idea I don’t want to pass to my components library the current ‘theme’ but each time the application started, it sets the context and components automatically consume that value.
What is the expected behavior? Consumer components should have the same value as the provider.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
"react": "=16.12.0"
Is this because I create an npm module for ThemeContext ? I should have an npm package ThemeContext because many apps will consume it 😦
Thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Thanks for the update 👍
I found why, this is due to storybook, I get everything works perfectly without storybook, I created a separated project and import all dependencies. Thank you so much for your help @bvaughn 👍 😃 https://codesandbox.io/s/funny-pascal-w950v