pmndrs / react-three-next

React Three Fiber, Threejs, Nextjs starter
https://react-three-next.vercel.app/
MIT License
2.52k stars 342 forks source link

Component.canvas doesn't reset when changing route #114

Closed ctian1 closed 1 year ago

ctian1 commented 1 year ago

Hooks inside of Component.canvas seem to break because the component doesn't properly unmount and remount when switching routes, and React thinks they should be the same instance. I fixed it by passing the route as a key:

<Component.canvas key={path} {...pageProps} />

RenaudRohlinger commented 1 year ago

The goal of the starter is to not unmount the canvas while switching routes, it allows developers to make smooth 3D transitions while navigating between pages.

If you need to unmount or remount your canvas component I can only recommend embedding <Component.canvas /> in your page instead of at the app root.