Giter Club home page Giter Club logo

Comments (6)

danielr18 avatar danielr18 commented on June 21, 2024

I think the most simple implementation would be something like this:

import { createStore } from 'redux'

function initStore() {
  // all store initialization logic
  return createStore();
}

export default function App({ Component, pageProps }) {
  const [store, setStore] = useState(initStore)

  useEffect(() => {
    /** 
    initialize the app after mount if initStore should behave different 
    in server and client, to avoid hydration issues.
    **/
    setStore(initStore());
  }, []);

  return (
    <Provider store={store}>
      <ConnectedRouter>
        <Component {...pageProps} />
      </ConnectedRouter>
    </Provider>
  )
}

from connected-next-router.

kylemh avatar kylemh commented on June 21, 2024

Hey @danielr18 still working in this area as I've run into a strange issue. If I've got a separation in my store initializer around if window is defined or not (if it's CSR or not), would I want to run:

  const routerMiddleware = createRouterMiddleware()
  const { asPath, pathname, query } = context.ctx || Router.router || {};
  let initialState
  if (asPath) {
    const url = format({ pathname, query })
    initialState = {
      router: initialRouterState(url, asPath)
    }
  }
  return createStore(rootReducer, initialState, applyMiddleware(routerMiddleware))

for both cases?

edit: No problem. I just wanted to confirm my thoughts.

from connected-next-router.

danielr18 avatar danielr18 commented on June 21, 2024

@kylemh Probably, you would want to have the same initial state in the server and client to prevent hydrate mismatches.

What's the issue you are seeing?

from connected-next-router.

Prof-isaac avatar Prof-isaac commented on June 21, 2024

Hi @danielr18 I have issue with connected next router It affects all the push that have query params

from connected-next-router.

danielr18 avatar danielr18 commented on June 21, 2024

@Prof-isaac can you create a new issue and add more details?

from connected-next-router.

Prof-isaac avatar Prof-isaac commented on June 21, 2024

@danielr18 thanks for your quick response.
after wrapping my app with ConnectedRouter e.g



<Component {...pageProps} />


this router.push from next/router in my project gives me error, but when i remove the ConnectedRouter it will work properly
router.push({
pathname: home/${productName}/${id}/view,
query: { previousLabel }
})

here is the error====================>
Unhandled Runtime Error
TypeError: url.startsWith is not a function

Source
next-server\lib\router\router.ts (97:6) @ isLocalURL

95 | */
96 | export function isLocalURL(url: string): boolean {

97 | if (url.startsWith('/')) return true
| ^
98 | try {
99 | // absolute urls can be local if they are on the same origin
100 | const locationOrigin = getLocationOrigin()
Call Stack
Object.instance. [as push]
client\router.ts (165:13)
Show collapsed frames

from connected-next-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.