Skip to content

Commit

Permalink
examples/nextjs-with-typescript: Make _app.js functional
Browse files Browse the repository at this point in the history
  • Loading branch information
HaNdTriX committed Apr 2, 2020
1 parent 7f3e662 commit c5aa16b
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions examples/nextjs-with-typescript/pages/_app.tsx
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>
);
}

0 comments on commit c5aa16b

Please sign in to comment.