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

better way to access `scene` in children

Open kevzettler opened this issue 8 years ago • 2 comments

I've had a few cases now where I've needed access to the scene reference to call methods on the THREE.scene object. I'm purposing adding this as a property to context. This would be similar to how react-redux handles passing store down the tree.

The current options for accessing this could be better. Let me know if I am missing better options. Currently, I see the following options.

  • Using refs I can give scene a ref and children a ref and at the top of the react tree I can do this.refs.scene.refs.customcomponent.refs.mesh

  • Using parent On in the child component, I can crawl back up the tree doing. mesh.parent.parent.parent.someSceneMethod()

  • Usingrefs and props At the top of the tree I can do can create a scene ref and pass it down as a prop to children.

kevzettler avatar Nov 28 '16 05:11 kevzettler

I think using refs and props would be "the react way" of doing it, but you could also probably use a shared variable (e.g. require a file (that defines a simple container object) in multiple other files and access properties to set/get things like the scene

toxicFork avatar Jan 03 '17 11:01 toxicFork

I can also think of a module to get and set custom data on objects but that would be quite complicated. From my tests using context can work too but if it doesn't it can be fixed!

toxicFork avatar Jan 03 '17 11:01 toxicFork