import React from 'react' ; import App , { AppProps } from 'next/app' ; import { END } from 'redux-saga' ; import { SagaStore , wrapper } from '../components/store' ; class MyApp extends React . Component < AppProps > { public static getInitialProps = wrapper . getInitialAppProps ( store => async ( context ) => { const pageProps = { ... ( await App . getInitialProps ( context ) ) . pageProps , } ; if ( context . ctx . req ) { store . dispatch ( END ) ; await ( store as SagaStore ) . sagaTask . toPromise ( ) ; } return { pageProps } ; } ) ; public render ( ) { const { Component , pageProps } = this . props ; return < Component { ... pageProps } / > ; } } export default wrapper . withRedux ( MyApp ) ;