ThemeProvider doesn't work as expect
See original GitHub issueFrom the documentation
In the render tree all styled-components will have access to the provided theme, even when they are multiple levels deep.
So I did this https://github.com/straw-hat-team/impetus_bit/blob/master/src/OTP/Core/Application.js#L40
render() {
const shouldShowLoadingScreen = this.showLoadingScreen()
const children = shouldShowLoadingScreen ? this.renderLoadingScreen() : this.renderBody()
return (
<Provider applicationStore={this.store}>
<IntlProvider locale={navigator.language}>
<ThemeProvider theme={Theme}>
<BaseHold baseline={Theme.baseline} ratio={Theme.ratio} unit={Theme.unit}>
{children}
</BaseHold>
</ThemeProvider>
</IntlProvider>
</Provider>
)
}
So notice I add my ThemeProvider
but when I do console.log(this.props.theme)
doesn’t show any theme
key
Expected Behavior
I should see theme
key in the props in all the components from that HoC in.
Actual Behavior
I don’t see the theme
key in the props
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why is ThemeProvider (Material UI) not working for me here?
Checking the documents of material-ui it turns out you have imported some of the things from library in a wrong way. Like the...
Read more >Theming with React and MUI - Welcome, Developer
MUI provides a ThemeProvider component that provides the theme to all the UI components in the app. This component expects a theme object...
Read more >Advanced (LEGACY) - MUI System
Add a ThemeProvider to the top level of your app to pass a theme down the React component ... Applying withStyles(styles) as a...
Read more >API Reference - styled-components
ThemeProvider. A helper component for theming. Injects the theme into all styled components anywhere beneath it in the component tree, ...
Read more >Troubleshooting | React Navigation
If the module points to an npm package (i.e. the name of the module doesn't with ./ ), then it's probably due to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
“In the render tree all styled-components will have access to the provided theme, even when they are multiple levels deep.”
Note how it says “styled-components” and NOT “react components”. Only all
styled-components
have access to the theme, like so:If you want to get the theme in your normal React component you have to use our
withTheme
higher order component:Next time when you have a usage question please ask in the community or on StackOverflow, this is an issue tracker. Thanks!
This is likely a usage problem, please post the code where you do
console.log(this.props.theme)
.