next-redux-wrapper
next-redux-wrapper copied to clipboard
parameter 'context' is empty for makeStore function
Describe the bug
I am trying to setup a new Next.js project (v13 but using pages directory routing)
// create a makeStore function
const makeStore = (context: Context) => createStore(reducer);
Code above is from the readme. After investigation, nothing gets passed on to the function. I need function to be called with context so that I can use it with connected-next-router which uses the context as follows
export const initStore = (context) => {
const routerMiddleware = createRouterMiddleware()
const { asPath } = context.ctx || Router.router || {}
let initialState
if (asPath) {
initialState = {
router: initialRouterState(asPath)
}
}
return createStore(reducer, initialState, applyMiddleware(routerMiddleware))
}
export const wrapper = createWrapper(initStore)
code above is from example in connected-next-router repo where initStore is equivalent to makeStore
if I get next-redux-wrapper + connected-next-router combined
initialState of router will always be even when the url is something like localhost:3000/some/path
{
router: {
location: {
href: '/',
pathname: '/',
search: '',
hash: ''
}
}
}
To Reproduce
https://codesandbox.io/s/exciting-pasteur-3tl57q well I just took the template and added console.log to the makeStore function if that would help
Expected behavior
context need to be passed on to the initStore in useWrappedStore
// next-redux-wrapper/src/index.tsx:235
// change to {makeStore, context} maybe?
const store = useMemo<S>(() => initStore<S>({makeStore}), []);
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Mac
- Browser chrome
- Version
"next": "13.4.7",
"next-redux-wrapper": "^8.1.0",
"connected-next-router": "^4.2.0",
I looked at my older project and same thing happened which was using
"connected-next-router": "^4.1.1",
"next": "12.2.5",
"next-redux-wrapper": "^7.0.5",
Additional context
Add any other context about the problem here.
I couldn't tell if initial state always being resolved to '/' is intentional could be a question or could be a bug
thank you