Skip to content
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

parameter 'context' is empty for makeStore function #554

Open
cjhdom opened this issue Jul 18, 2023 · 0 comments
Open

parameter 'context' is empty for makeStore function #554

cjhdom opened this issue Jul 18, 2023 · 0 comments
Labels

Comments

@cjhdom
Copy link

cjhdom commented Jul 18, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant