-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/nextjs-with-typescript: Make _app.js functional
- Loading branch information
Showing
1 changed file
with
19 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
import React from 'react'; | ||
import App from 'next/app'; | ||
import React, { useEffect } from 'react'; | ||
import Head from 'next/head'; | ||
import { AppProps } from 'next/app' | ||
import { ThemeProvider } from '@material-ui/core/styles'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import theme from '../src/theme'; | ||
|
||
export default class MyApp extends App { | ||
componentDidMount() { | ||
export default function MyApp({ Component, pageProps }: AppProps) { | ||
useEffect(() => { | ||
// Remove the server-side injected CSS. | ||
const jssStyles = document.querySelector('#jss-server-side'); | ||
const jssStyles = document.getElementById('jss-server-side'); | ||
if (jssStyles) { | ||
jssStyles.parentElement!.removeChild(jssStyles); | ||
} | ||
} | ||
}, []); | ||
|
||
render() { | ||
const { Component, pageProps } = this.props; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Head> | ||
<title>My page</title> | ||
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" /> | ||
</Head> | ||
<ThemeProvider theme={theme}> | ||
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */} | ||
<CssBaseline /> | ||
<Component {...pageProps} /> | ||
</ThemeProvider> | ||
</React.Fragment> | ||
); | ||
} | ||
return ( | ||
<React.Fragment> | ||
<Head> | ||
<title>My page</title> | ||
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" /> | ||
</Head> | ||
<ThemeProvider theme={theme}> | ||
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */} | ||
<CssBaseline /> | ||
<Component {...pageProps} /> | ||
</ThemeProvider> | ||
</React.Fragment> | ||
); | ||
} |