-
-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with custom App component #80
Comments
Moving a bit further I managed to get rid of the wrapper just by using a custom function getOrCreateStore(initialState = {}, req) {
let isBrowser = typeof window !== 'undefined';
let store = null;
if (isBrowser) {
// Memoize store on client
if (!window['reduxStore']) {
store = initStore(initialState, {});
window['reduxStore'] = store;
} else {
store = window['reduxStore'];
}
} else {
// Server store
store = initStore(initialState, { req });
}
return store;
}
export default class MyApp extends App {
static async getInitialProps({ Component, router, ctx }) {
let pageProps = {};
// Redux store
let store = getOrCreateStore(ctx.req);
ctx.store = store;
// Page props
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx);
}
return { pageProps, store, initialState: store.getState() };
}
render() {
const { Component, pageProps, initialState } = this.props;
return (
<Container>
<Provider store={store && store.dispatch ? store : getOrCreateStore(initialState)}>
<Component {...pageProps} />
</Provider>
</Container>
);
}
} |
Thanks for your interest and recommendation, I will release a new version for |
Pushed stuff to |
Released |
That was fast, thanks 👍 |
Awesome. I will keep it in |
Hi and thanks for your wrapper !
I'm using it fine on each page of my application. I recently updated my next app with v6 to extend the app component (see vercel/next.js#4129) and was wondering if maybe we could use this new extension point to improve the integration of the wrapper.
This could be great if instead of repeating this code we could have a standard React Redux connect for the pages.
The text was updated successfully, but these errors were encountered: