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

Why store router on zustand if router is already available via useRouter? #69

Closed
hems opened this issue Feb 1, 2022 · 6 comments
Closed
Labels
question Further information is requested

Comments

@hems
Copy link

hems commented Feb 1, 2022

I'm curious about what's the advantage / goal of storing router on zustand if it's already available via useRouter ?

const router = useRouter()
useEffect(() => {
useStore.setState({ router })
}, [router])

const router = useStore((state) => state.router)

const router = useStore((s) => s.router)

@marceloavf
Copy link

I'm trying to reproduce a bug here, and I'm thinking that it's because of it.

If I use the router directly from next seems to bug some interactions because of R3F.

@RenaudRohlinger
Copy link
Member

Hello!

It is because context is lost through the reconciler. So we have to either way forward it through context bridge or via a state manager such as Zustand.

If that answers your question feel free to close this issue. Maybe we could add a small explanation in the readme

@RenaudRohlinger RenaudRohlinger added the question Further information is requested label Feb 5, 2022
@hems
Copy link
Author

hems commented Feb 7, 2022

If you just import "Router" directly instead of "useRouter" won't that fix the issues?

i.e.

import Router from 'next/router'

Router.whateverYouNeed

@emalorenzo
Copy link
Contributor

Hello!

It is because context is lost through the reconciler. So we have to either way forward it through context bridge or via a state manager such as Zustand.

If that answers your question feel free to close this issue. Maybe we could add a small explanation in the readme

I need to reload the page to see the dom changes every time. Is this something related to that?

@RenaudRohlinger
Copy link
Member

latest r3f fix this

@synztran
Copy link

If you just import "Router" directly instead of "useRouter" won't that fix the issues?

i.e.

import Router from 'next/router'

Router.whateverYouNeed

It works. useRouter cannot be used. But the Router works.

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

No branches or pull requests

5 participants