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

Allow pass custom store by props

Open rubeniskov opened this issue 1 year ago • 1 comments
trafficstars

Currently there is no way to access the store outside the canvas context for some applications is usefull to have access to the canvas store outside its context for get scene graph, get stats or manage the event loop outside the canvas context (ie pause, advance nframes etc...)

rubeniskov avatar Feb 23 '24 11:02 rubeniskov

This is very internal to R3F, so we can't open this up as a prop, such as in #3179. I would instead propose hoisting up references to state methods via context or the get() callback from useThree(). Ideally, state will propogate downwards, which prevents bugs in the long run and encourages the component encapsulation model of React -- you should be able to unmount components and their effects remain side-effect free. If you must hold a reference to the store, such as for subscriptions, you can get a handle over the Zustand store via useStore().

CodyJasonBennett avatar Jan 09 '25 11:01 CodyJasonBennett