Skip to content

Instantly share code, notes, and snippets.

@eyerean
Created August 20, 2019 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyerean/84210966cc8822d88260c3c08c891981 to your computer and use it in GitHub Desktop.
Save eyerean/84210966cc8822d88260c3c08c891981 to your computer and use it in GitHub Desktop.
ThemeProvider combining styled-components and material-ui in typescript
import * as React from 'react';
import {ThemeProvider as StyledThemeProvider} from 'styled-components';
import {MuiThemeProvider} from '@material-ui/core/styles';
import {StylesProvider} from '@material-ui/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import {theme, muiTheme} from './';
interface ThemeProviderProps {
children: React.ReactNode
};
const ThemeProvider = ({ children }: ThemeProviderProps) => {
const nextTheme = {...theme, ...muiTheme};
return (
<StylesProvider injectFirst={true}>
<CssBaseline />
<StyledThemeProvider theme={nextTheme}>
<MuiThemeProvider theme={nextTheme}>{children}</MuiThemeProvider>
</StyledThemeProvider>
</StylesProvider>
)
}
export default ThemeProvider;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment