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

[fix] useTransition ref handling #1493

Merged
merged 2 commits into from
May 10, 2021
Merged

Conversation

joshuaellis
Copy link
Member

@joshuaellis joshuaellis commented May 8, 2021

Why

useTransition was not passing its ref as part of the payload, this the controllers (each item has a controller) were not being attached. This caused failures in instances such as useChain.

This resolves #1453

What

Pass the ref as part of the payload. However, when passing a ref, transitions will not be called unless ref.start is called, this is important and an example of what this looks like can be seen here: https://codesandbox.io/s/goofy-allen-u4hml?file=/src/App.tsx

I've also added the same API pattern that useSprings has, where only supplying a function as a prop argument will return a ref like so:

const [transition, transApi] = useTransition(items, () => ({ ...props }))

Checklist

  • Documentation updated – we're going on to beta so won't do yet.
  • Demo added
  • Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 8, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 32a897f:

Sandbox Source
spring-card Configuration
spring-goo-blobs Configuration
spring-flip-card Configuration
spring-slide Configuration
spring-draggable-list Configuration
spring-cards-stack Configuration
spring-viewpager Configuration
spring-simple-transition Configuration
spring-image-fade Configuration
spring-list-reordering Configuration
compassionate-turing-g38gx PR
admiring-meadow-x3uyx Issue #1453

@joshuaellis
Copy link
Member Author

@dbismut See the sandbox above, do you think it's weird that you even if you change the transition data, you need to call start to trigger said animation? I find it odd to begin with when thinking in isolation of the useTransition hook but as a whole compared to our other hooks, it's consistent which I prefer. Good to hear your thoughts 🤔

@joshuaellis joshuaellis linked an issue May 8, 2021 that may be closed by this pull request
@joshuaellis joshuaellis merged commit 0c4e45d into beta May 10, 2021
@joshuaellis joshuaellis deleted the fix/useTransition-ref-handling branch May 10, 2021 19:50
@dbismut
Copy link
Contributor

dbismut commented May 10, 2021

@joshuaellis I agree that having a consistent API across hooks is instrumental, so yes I support this PR 💪

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

Successfully merging this pull request may close these issues.

useChain does not work as expected for transitions
2 participants