LoginSignup
0
0

More than 3 years have passed since last update.

【TypeScript】Next.jsでAppバーを共通化する方法

Posted at

_app.tsxにAppバーコンポーネントを追加する

以下参考プログラムです。

_app.tsx
import React from "react";
import App from "next/app";
import Bar from "../components/Bar";

export default class MyApp extends App {
  static async getInitialProps({
    Component,
    ctx
  }: {
    Component: any;
    ctx: any;
  }) {
    let pageProps = {};

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

    return { pageProps };
  }

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

    return (
      <React.Fragment>
        <Bar />
        <Component {...pageProps} />
      </React.Fragment>
    );
  }
}


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0