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

Trouble using {config: (key) => ...} with useTrail #590

Closed
cwgw opened this issue Mar 12, 2019 · 5 comments
Closed

Trouble using {config: (key) => ...} with useTrail #590

cwgw opened this issue Mar 12, 2019 · 5 comments

Comments

@cwgw
Copy link

cwgw commented Mar 12, 2019

When I set config as a function in useTrail, it doesn't get called with the arguments I'd expect.

I'd love to be able to do something like below with useTrail, but currently the key parameter I get is not a reference to the animated value; rather, it's a reference to each spring's index in the set.

const trail = useTrail(items.length, {
  to: {
    opacity: 0,
    translateY: 50,
  },
  config: (key) => ({
    clamp: key === 'opacity'
    ...

Rather than getting opacity and translateY, I'm getting 0, 1, 2, etc. I imagine this might be by design, but it'd be great to get both the key and index.

I love this library by the way. Thank you for all of the great work!

@Mathspy
Copy link

Mathspy commented Mar 12, 2019

Disclaimer: I am also new to this so everything ahead might be completely incorrect
This is by design, I think, as having multiple configurations is basically having multiple different "springs". The idiomatic way of doing this would be using several useTrails, each with a different property (one for opacity, one for translateY). If there are a lot of duplicate settings you can extract those to an object that you spread

The key => config functionality is used when you want each individual item of your trail to have a different configuration

@aleclarson
Copy link
Contributor

The config function is called items.length times. It lets you customize each spring individually, as @Mathspy said. It would be easier to help you if you provided a CodeSandbox. Closing for now.

@sjnonweb

This comment has been minimized.

@aleclarson
Copy link
Contributor

@sjnonweb If you're talking about the v9 beta, please open a new issue. Thanks!

@sjnonweb
Copy link

sjnonweb commented Apr 29, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants