You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** child.js */importReactfrom'react';importstyledfrom'react-emotion';constContainer=styled.div` background: whitesmoke; height: 100vh;`;constHeadline=styled.h1` color: ${props=>props.theme.color}; font: 20px/1.5 sans-serif;`;exportdefaultPageextendsReact.Component{render(){return(<Container><Headline>
Im red!
</Headline></Container>);}}/** parent.js */importReactfrom'react';importReactDOMfrom'react-dom';import{ThemeProvider}from'emotion-theming';importPagefrom'./child.js';consttheme={color: 'red',};classAppextendsReact.Component{render(){return(<ThemeProvidertheme={theme}><Page/></ThemeProvider>);}}// this assumes the HTML page template has a <main> element already inside <body>ReactDOM.render(<App/>,document.querySelector('main'));
Hi.
emotion
version:^7.3.2
emotion-theming
version:^8.0.2-10
react
version:^16.0.0
Relevant code (copy-paste from the emotion-theming#usage docs):
What you did:
I just tried to run the example from the docs 😅.
What happened:
Reproduction:
Run the code from the docs.
Problem description:
Running the example from the emotion-theming#usage docs throws the
Uncaught TypeError: Cannot read property 'color' of undefined
.Seems like
theme
is not passed through context to descendants of<ThemeProvider>
. The only workaround is to explicitly usewithTheme
HOC, i.e.:Suggested solution:
😅
The text was updated successfully, but these errors were encountered: