next-redux-wrapper icon indicating copy to clipboard operation
next-redux-wrapper copied to clipboard

Cannot read properties of undefined (reading 'dispatch')

Open mezhinsky opened this issue 3 years ago • 0 comments

Describe the bug

Getting TypeError: Cannot read properties of undefined (reading 'dispatch') After update from 6.0.2 to 7.0.5

To Reproduce

here _App.tsx

import React from 'react'; import App, {AppInitialProps, AppContext} from 'next/app'; import {END} from 'redux-saga'; import { wrapper, SagaStore } from '../store/store';

class MyApp extends App<AppInitialProps> { public static getInitialProps = async ({Component, ctx}: AppContext) => { const pageProps = { ...(Component.getInitialProps ? await Component.getInitialProps(ctx) : {}), };

	if (ctx.req) {
			ctx.store.dispatch(END);
			await (ctx.store as SagaStore).sagaTask?.toPromise();
	}

	return {
			pageProps,
	};

};

render() {
	const { Component, pageProps } = this.props;

	return (
		<React.Fragment>
			<Component {...pageProps} />
		</React.Fragment>
	);
}

}

export default wrapper.withRedux(MyApp);

Expected behavior

A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: MacOs 12.1
  • Browser Chrome
  • Version 7.0.5

Additional context

Add any other context about the problem here.

mezhinsky avatar Dec 27 '21 23:12 mezhinsky