Unable to add theme to any Styled component for even basic usage
See original GitHub issueI tried basic implementation of Theming Styled components, as shown in the documentation Styled component Theming
I tried with my basic parent component,
const theme = {
main: 'mediumseagreen'
};
const Button = styled.button`
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border-radius: 3px;
/* Color the border and text with theme.main */
color: ${props => props.theme.main};
border: 2px solid ${props => props.theme.main};
`;
ReactDOM.render(
<ThemeProvider theme={theme}>
<Button>Themed</Button>
</ThemeProvider>,
document.getElementById('root')
);
build passes but browser consoles an Error
**Uncaught Error: Cannot create styled-component for component: [object Object]**
at constructWithOptions (styled-components.es.js:2089)
at styled (styled-components.es.js:2024)
at mountIndeterminateComponent (react-dom.development.js:8038)
at beginWork (react-dom.development.js:8229)
at performUnitOfWork (react-dom.development.js:10215)
at workLoop (react-dom.development.js:10279)
at HTMLUnknownElement.callCallback (react-dom.development.js:540)
at Object.invokeGuardedCallbackDev (react-dom.development.js:579)
at invokeGuardedCallback (react-dom.development.js:436)
at renderRoot (react-dom.development.js:10357)
Using Chrome Browser, with project dependencies
"dependencies": {
"react": "^16.1.0",
"react-dom": "^16.1.0",
"styled-components": "^2.2.3"
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (9 by maintainers)
Top Results From Across the Web
Advanced Usage - styled-components
This component provides a theme to all React components underneath itself via the context API. In the render tree all styled-components will have...
Read more >How to use Themes in styled-components - DEV Community
First things first, import React from the react dependency, and then we import ThemeProvider from the styled-components file. Theme provider ...
Read more >Theming and Theme Switching with React and styled ...
Let's set up a project with React and styled-components. ... This component is responsible for providing the theme to all other React ...
Read more >Build a React theme switcher app with styled-components
In this tutorial, we demonstrate how to build a custom theme switcher for a Game of Thrones-themed React app using styled-components.
Read more >Theme with styled-components and Typescript - Medium
Create a theme. Once we defined our theme interface, we can import DefaultTheme to our theme file and assign all theme values. ·...
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
@mxstbr What the hell is this, Max: (!!!)
@mukurpuri You need to delete that and change the import to this:
@morajabi Thank you brother for pointing this silly mistake. But there was no point to make a laugh out of this. If it was so silly, I had rather appreciate the explanation but not an emojical fun.