1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-material-ui-next/styles/createDefaultContext.js
2017-07-13 13:11:20 +02:00

39 lines
997 B
JavaScript

import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
import createPalette from 'material-ui/styles/palette'
import createMuiTheme from 'material-ui/styles/theme'
import { purple, green } from 'material-ui/colors'
const createDefaultContext = () =>
MuiThemeProvider.createDefaultContext({
theme: createMuiTheme({
palette: createPalette({
primary: purple,
accent: green
})
})
})
// Singleton hack as there is no way to pass variables from _document.js to pages yet.
let context = null
export function setDefaultContext () {
context = createDefaultContext()
}
export function getDefaultContext () {
// Make sure to create a new store for every server-side request so that data
// isn't shared between connections (which would be bad)
if (!process.browser) {
return context
}
// Reuse store on the client-side
if (!context) {
context = createDefaultContext()
}
return context
}
export default createDefaultContext