Skip to content

Commit 116ae46

Browse files
authored
Merge pull request #9 from treetips/feature/ctx_type
Change ctx type from any to custom type
2 parents 3823c42 + 97b15ff commit 116ae46

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

components/AppContext.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NextDocumentContext } from "next/document"
2+
import { Store } from "redux"
3+
4+
/**
5+
* NextDocumentContext with redux store context
6+
* @tree
7+
*/
8+
export type AppContext = NextDocumentContext & {
9+
readonly store: Store
10+
}

pages/_document.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { ServerStyleSheets } from "@material-ui/styles"
2-
import Document, { Head, Main, NextScript } from "next/document"
3-
import React from "react"
4-
import flush from "styled-jsx/server"
5-
import { MuiTheme } from "../components/MuiTheme"
6-
import "../styles/main.css"
1+
import { ServerStyleSheets } from "@material-ui/styles";
2+
import Document, { Head, Main, NextScript } from "next/document";
3+
import React from "react";
4+
import flush from "styled-jsx/server";
5+
import { AppContext } from "../components/AppContext";
6+
import { MuiTheme } from "../components/MuiTheme";
7+
import "../styles/main.css";
78

89
interface IProps {
910
pageProps: any
@@ -13,7 +14,7 @@ interface IProps {
1314
* @see https://github.com/mui-org/material-ui/blob/master/examples/nextjs-with-typescript/pages/_document.tsx
1415
*/
1516
class MyDocument extends Document<IProps> {
16-
static getInitialProps = async ctx => {
17+
static getInitialProps = async (ctx: AppContext) => {
1718
// Render app and page and get the context of the page with collected side effects.
1819
const sheets = new ServerStyleSheets()
1920

pages/about.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Typography } from "@material-ui/core"
22
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"
33
import React from "react"
4+
import { AppContext } from "../components/AppContext"
45
import { SpacingPaper } from "../components/atoms"
56
import { HeaderArticleContainer } from "../components/organisms"
67
import { Layout } from "../components/templates"
@@ -29,7 +30,7 @@ function About() {
2930
/**
3031
* Server side rendering
3132
*/
32-
About.getInitialProps = async ctx => {
33+
About.getInitialProps = async (ctx: AppContext) => {
3334
const pagePayload: IPagePayload = {
3435
selectedPage: Page.ABOUT,
3536
}

pages/redux.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"
99
import React, { useState } from "react"
1010
import { useDispatch, useSelector } from "react-redux"
11+
import { AppContext } from "../components/AppContext"
1112
import { SpacingPaper } from "../components/atoms"
1213
import { HeaderArticleContainer } from "../components/organisms"
1314
import { Layout } from "../components/templates"
@@ -121,7 +122,7 @@ function Redux() {
121122
/**
122123
* Server side rendering
123124
*/
124-
Redux.getInitialProps = async ctx => {
125+
Redux.getInitialProps = async (ctx: AppContext) => {
125126
const pagePayload: IPagePayload = {
126127
selectedPage: Page.REDUX,
127128
}

0 commit comments

Comments
 (0)