Skip to content

Instantly share code, notes, and snippets.

@storybynumbers
Last active November 16, 2018 14:55
Show Gist options
  • Save storybynumbers/c000a8599f84987103f5dfefa43646f4 to your computer and use it in GitHub Desktop.
Save storybynumbers/c000a8599f84987103f5dfefa43646f4 to your computer and use it in GitHub Desktop.
Wrapping styled components themeprovider without breaking next.js SSR
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { loadGetInitialProps } from 'next/dist/lib/utils';
const MyTheme = {
fontSizes: [
12, 14, 16, 20, 24, 32, 48, 64
]
};
expose default ComposedComponent => class withTheme extends React.Component {
static async getInitialProps(ctx) {
return loadGetInitialProps(ComposedComponent, ctx);
}
render() {
return (
<ThemeProvider theme={MyTheme}>
<ComposedComponent {...this.props} />;
</ThemeProvider>
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment