Skip to content

Instantly share code, notes, and snippets.

@radicalloop
Created March 2, 2020 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radicalloop/5eee42366221416430ab54cd8e96e1dc to your computer and use it in GitHub Desktop.
Save radicalloop/5eee42366221416430ab54cd8e96e1dc to your computer and use it in GitHub Desktop.
Overwrite "App" component in Next.js
import React from 'react'
import { Provider } from 'react-redux'
import withRedux from 'next-redux-wrapper'
import { initStore } from '../store/store'
import App from 'next/app';
const MyApp = props => {
const { Component, pageProps, store } = props
return (
<Provider store={store}>
<Component {...pageProps} />
</Provider>
)
}
MyApp.getInitialProps = async (appContext) => {
// calls page's `getInitialProps` and fills `appProps.pageProps`
const appProps = await App.getInitialProps(appContext);
return { ...appProps }
}
export default withRedux(initStore)(MyApp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment