Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve custom App component. #131

Merged
merged 1 commit into from
May 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import App from "next/app";
import Head from "next/head";
import React from "react";
import config from "../config/config.example.yml";
// The CI would complain about the missing config file if the rule was not ignored.
// Reason: at build-time, the config comes from an environment variable so it's not committed directly to the repository.
// eslint-disable-next-line import/no-unresolved
import config from "../config/config.yml";

export default class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
let pageProps = {};
const app = ({ Component, pageProps }) => (
<>
<Head>
<title>{config.name}</title>
</Head>
<Component {...pageProps} />
</>
);

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx);
}

return { pageProps };
}

render() {
const { Component, pageProps } = this.props;

return (
<>
<Head>
<title>{config.name}</title>
</Head>
<Component {...pageProps} />
</>
);
}
}
export default app;