Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return ref of tween target #19

Closed
fitzmode opened this issue May 20, 2020 · 7 comments
Closed

Return ref of tween target #19

fitzmode opened this issue May 20, 2020 · 7 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@fitzmode
Copy link

Hey there. Seems Tween does not return the ref of it's children.

Here's a demo https://codesandbox.io/s/wizardly-mclaren-7oswj?file=/src/App.js

@bitworking
Copy link
Owner

Hmm, the Tween needs the ref by his own and overwrites it in this case. I could try to first get the ref and set it with the new ref var. But why exactly you need it?

@fitzmode
Copy link
Author

I need the ref to call methods on the node. Used div as a a contrived reproducible example.

@bitworking
Copy link
Owner

bitworking commented May 20, 2020

Ok let me try later. You also could get the refs with a tweenref.current.getGSAP().targets() call.

Look here: https://bitworking.github.io/react-gsap/src-instructions-low-level-access

@bitworking
Copy link
Owner

I tried it but cannot set the ref, because it's readonly. I saw your lib (https://github.com/fitzmode/use-dynamic-refs). You perhaps can help me with this?

I do the following, which probably could be optimized, too:

https://github.com/bitworking/react-gsap/blob/master/packages/react-gsap/src/Tween.tsx#L204

React.Children.map(children, child => {
  return React.cloneElement(child, {
    ref: target => {
      this.addTarget(target);
      // this doesn't work and I don't know if
      // setting the target to child.ref is the way to go
      child.ref = target;
    },
  });
})

@fitzmode
Copy link
Author

Let me work on it and will come back with a PR

@bitworking bitworking added bug Something isn't working enhancement New feature or request labels Mar 31, 2021
@bitworking
Copy link
Owner

I found a solution: facebook/react#8873 (comment)

Will be in next version.

@bitworking
Copy link
Owner

Fixed with version 2.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants