Last active
November 16, 2018 14:55
-
-
Save storybynumbers/c000a8599f84987103f5dfefa43646f4 to your computer and use it in GitHub Desktop.
Wrapping styled components themeprovider without breaking next.js SSR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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