danielr18 / connected-next-router

A Redux binding for Next.js Router compatible with Next.js.
MIT License
109 stars 30 forks source link

Integration in Saga #41

Closed dbrrt closed 4 years ago

dbrrt commented 4 years ago

Hello,

Is it possible to use this library in Redux Saga, if so how?

Thanks in advance.

danielr18 commented 4 years ago

@dbrrt Hello, it's possible to use it.

It depends on what you want to do, you can dispatch Router methods from your sagas, or read the location state from the store.

Let me know if I can help you further

dbrrt commented 4 years ago

@danielr18 Thanks for the quick reply, I've tried to wrap my main App with <Provider> and <ConnectedRouter>, but it had no effect when calling actions from the library. I'm using hooks in my functional components can it be an anti-pattern with your library?

danielr18 commented 4 years ago

Are you using the redux middleware?

Here's v2 example: https://github.com/danielr18/connected-next-router/tree/v2/examples/basic

dbrrt commented 4 years ago

Yes, but probably misconfigured. Will try again. Thanks for the link!

EDIT: Quickly adapted from the example your shared. It works just fine with Saga.

Here's how I'm updating the route in my sagas in my generators. yield put(push({ pathname: '/new-path'}))

Unfortunately I'm still having Server side rendering issues: Error: No router instance found. You should only use "next/router" inside the client side of your app.

danielr18 commented 4 years ago

Are you dispatching a navigation action on the server side?

dbrrt commented 4 years ago

That was the issue, performing the dispatch on the client side only resolved the problem

dbrrt commented 4 years ago

Thanks a lot @danielr18, this issue can be closed, I can try to make a PR with an example for Saga once I've got a moment.

danielr18 commented 4 years ago

@dbrrt That would be great, thanks!