Theming with styled-components
See original GitHub issueI’ve described the problem here.
I try to inject styled-components theme to every page but I only get empty theme
Object prop passed.
import App, { Container } from "next/app"; // eslint-disable-line
import React from "react";
import { ThemeProvider } from "styled-components";
export default class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
let pageProps = {};
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx);
}
return { pageProps };
}
render() {
const { Component, pageProps } = this.props;
return (
<Container>
<ThemeProvider theme={{ color: 'blue' }}>
<Component {...pageProps} />
</ThemeProvider>
</Container>
);
}
}
Inside some page:
const A = styled.a`
color: ${props => {
console.log(props.theme); // "{}"
return "blue";
}};
`;
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Advanced Usage - styled-components
styled -components has full theming support by exporting a <ThemeProvider> wrapper component. This component provides a theme to all React components ...
Read more >Theming and Theme Switching with React and styled ...
styled -components: A flexible way to style React components with CSS. It provides out-of-the-box theming support using a wrapper component ...
Read more >How to use Themes in styled-components - DEV Community
Theming is a great tool to use within front-end applications. It also allows me to write way less code and be more consistent...
Read more >Adding themes to a React app using styled-components | Blog
Styles are scoped: unlike CSS classes, which are global and affect your entire document, styled-components styles are specific to your component ...
Read more >Build a React theme switcher app with styled-components
Efficiency: styled-components uses the React Context API which offers a Theme Context that we can pass a theme into as a prop, allowing...
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 FreeTop 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
Top GitHub Comments
Now it works in 6.0.0-canary.4
Also have the same issue with 8.1.0, working fine in 8.0.0