ERROR TypeError: makeStore is not a function

Total
12
Shares

Describe error

I create a store by redux and put it into _app.js in next but it has error:

Code

const theme = responsiveFontSizes(createMuiTheme());

const initStore = createStore(
  Reducers,
  initialState,
  applyMiddleware(thunkMiddleware)
);

const _App = withRedux(initStore)(
  class _App extends App {
    static async getInitialProps({ Component, ctx }) {
      let pageProps = {};
      if (Component.getInitialProps) {
        pageProps = await Component.getInitialProps(ctx);
      }

      return { pageProps };
    }

    constructor(props) {
      super(props);
    }

    componentDidMount() {
      fonts();
      const jssStyles = document.querySelector("#jss-server-side");
      if (jssStyles && jssStyles.parentNode) {
        jssStyles.parentNode.removeChild(jssStyles);
      }
    }

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

      return (
        <React.Fragment>
          <Head>
            <title>Doctor Finder</title>
            <meta
              name="viewport"
              content="minimum-scale=1, initial-scale=1, width=device-width"
            />
          </Head>
          <ThemeProvider theme={theme}>
            {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
            <CssBaseline />
            <Provider store={store}>
              <Component {...pageProps} />
            </Provider>
          </ThemeProvider>
        </React.Fragment>
      );
    }
  }
);

export default _App;

Error

/! You are using legacy implementaion. Please update your code: use
createWrapper() and wrapper.withRedux().

TypeError: makeStore is not a function

Thanks so much!!


Solution

Not sure what the withRedux api is but based on the error it seems it’s expecting a function but you are passing an object to it (initStore).

Try change initStore to something like this:

const initStore = () => createStore(
  Reducers,
  initialState,
  applyMiddleware(thunkMiddleware)
);
Leave a Reply

Your email address will not be published. Required fields are marked *