1//Now, we create our _app.js file in pages directory. Add the following lines of code.
2
3import React from "react";
4import App, { Container } from "next/app";
5import { Provider } from "react-redux";
6import withRedux from "next-redux-wrapper";
7import { initStore } from "../state/store";
8
9
10class MyApp extends App {
11 static async getInitialProps({ Component, ctx }) {
12 const pageProps = Component.getInitialProps
13 ? await Component.getInitialProps(ctx)
14 : {};
15 return { pageProps };
16 }
17
18
19 render() {
20 const { Component, pageProps, store } = this.props;
21 return (
22 <Container>
23 <Provider store={store}>
24 <Component {...pageProps} />
25 </Provider>
26 </Container>
27 );
28 }
29}
30
31
32export default withRedux(initStore)(MyApp);