react-three-next icon indicating copy to clipboard operation
react-three-next copied to clipboard

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

Open hems opened this issue 4 years ago • 4 comments

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

https://github.com/pmndrs/react-three-next/blob/8648c93e97ac9e2dc0fdfcb6b002eb3dd0418ca1/src/pages/_app.jsx#L26-L30

https://github.com/pmndrs/react-three-next/blob/8648c93e97ac9e2dc0fdfcb6b002eb3dd0418ca1/src/helpers/store.js#L5

https://github.com/pmndrs/react-three-next/blob/8648c93e97ac9e2dc0fdfcb6b002eb3dd0418ca1/src/components/canvas/Shader/Shader.jsx#L30

https://github.com/pmndrs/react-three-next/blob/8648c93e97ac9e2dc0fdfcb6b002eb3dd0418ca1/src/components/canvas/Box.jsx#L6

hems avatar Feb 01 '22 04:02 hems

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.

marceloavf avatar Feb 03 '22 13:02 marceloavf

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 avatar Feb 05 '22 01:02 RenaudRohlinger

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

i.e.

import Router from 'next/router'

Router.whateverYouNeed

hems avatar Feb 07 '22 21:02 hems

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?

emalorenzo avatar Mar 31 '22 20:03 emalorenzo

latest r3f fix this

RenaudRohlinger avatar Sep 29 '22 00:09 RenaudRohlinger