-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_app.tsx
55 lines (50 loc) · 1.77 KB
/
_app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import CssBaseline from '@material-ui/core/CssBaseline';
import { StylesProvider, ThemeProvider } from '@material-ui/styles';
import App, { Container } from 'next/app';
import Head from 'next/head';
// --- Post bootstrap -----
import React from 'react';
import '../src/bootstrap';
import getPageContext, { PageContext } from '../src/getPageContext';
class MyApp extends App {
constructor() {
// @ts-ignore
super();
this.pageContext = getPageContext();
}
componentDidMount() {
// Remove the server-side injected CSS.
const jssStyles = document.querySelector('#jss-server-side');
if (jssStyles && jssStyles.parentNode) {
jssStyles.parentNode.removeChild(jssStyles);
}
}
render() {
const { Component, pageProps } = this.props;
return (
<Container>
<Head>
<title>My page</title>
</Head>
{/* Wrap every page in Styles and Theme providers */}
<StylesProvider
generateClassName={this.pageContext.generateClassName}
sheetsRegistry={this.pageContext.sheetsRegistry}
sheetsManager={this.pageContext.sheetsManager}
>
{/* ThemeProvider makes the theme available down the React
tree thanks to React context. */}
<ThemeProvider theme={this.pageContext.theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
{/* Pass pageContext to the _document though the renderPage enhancer
to render collected styles on server side. */}
<Component pageContext={this.pageContext} {...pageProps} />
</ThemeProvider>
</StylesProvider>
</Container>
);
}
private pageContext: PageContext;
}
export default MyApp;