kirill-konshin / next-redux-wrapper

Redux wrapper for Next.js
MIT License
2.67k stars 266 forks source link

issue with next-redux-wrapper #527

Closed Shivamycodee closed 1 year ago

Shivamycodee commented 1 year ago

I don't understand why I'm getting this error:

TypeError: (0 , next_redux_wrapper__WEBPACK_IMPORTED_MODULE_4__.withRedux) is not a function

I'm just trying to use redux in next.js,

app.js file:

import '@/styles/globals.css' import { Provider } from "react-redux"; import {store} from "./store"; import { withRedux } from "next-redux-wrapper";

function App({ Component, pageProps }) { return <>

<Component {...pageProps} />

</> }

export default withRedux(store)(App);

store file:-

import { configureStore, createSlice } from "@reduxjs/toolkit"; const counterSlice = createSlice({ name: "counter", initialState: { value: 0, }, reducers: { increment: (state) => { state.value += 1; }, decrement: (state) => { state.value -= 1; }, }, });

export const { increment, decrement } = counterSlice.actions;

export const store = configureStore({ reducer: counterSlice.reducer, });

kirill-konshin commented 1 year ago

Which version are you using? Please provide codesandbox and please follow the template.

Shivamycodee commented 1 year ago

here is my whole code...

https://codesandbox.io/p/sandbox/bitter-silence-fj8khb?file=%2Fpages%2Fstore.js&selection=%5B%7B%22endColumn%22%3A7%2C%22endLineNumber%22%3A12%2C%22startColumn%22%3A7%2C%22startLineNumber%22%3A12%7D%5D

I'm getting error : TypeError: makeStore is not a function

kirill-konshin commented 1 year ago

Sandbox is broken:

image

Which version of wrapper are you using?

kirill-konshin commented 1 year ago

export const wrapper = createWrapper(store, { debug: true });

This is wrong, you should supply not the store, but a function that will make a store:

export const wrapper = createWrapper(() => configureStore({
  reducer: counterSlice.reducer,
}), { debug: true });

Please read the docs!