pmndrs / react-zdog

⚡️🐶 React bindings for zdog
MIT License
443 stars 21 forks source link

Allow access to the parent Illustration #8

Closed boardfish closed 5 years ago

boardfish commented 5 years ago

This has likely got a similar source to #7. useRender can only be used inside of Illustrations, but I'd like to be able to change the rotate attribute of an Illustration on a frame-by-frame basis as you would with:

function animate() {
  illo.rotate.y += 0.08
  requestAnimationFrame(animate)
}

Originally posted by @boardfish in https://github.com/drcmda/react-zdog/issues/7#issuecomment-499520438

drcmda commented 5 years ago

this is normal, its context based, and ultimatively there could be multiple illustrations, it has to be part of its tree to know the illustration it targets - no way around that. i could let you access the parent illu maybe, then you could still drive it in a loop (which is part of the component tree).

boardfish commented 5 years ago

I like that idea – while children in React should generally be oblivious to their parents, Shapes rely on Illustrations to exist, so in this case I think it makes sense to do it that way.

drcmda commented 5 years ago

it's in. useZdog, documented on the front page