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: assign controller to provided ref for useTransition #1475

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/core/src/hooks/useTransition.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RenderResult, render } from '@testing-library/react'
import { toArray } from '@react-spring/shared'
import { TransitionFn, UseTransitionProps } from '../types'
import { useTransition } from './useTransition'
import { SpringRef } from '../SpringRef'

describe('useTransition', () => {
let transition: TransitionFn
Expand Down Expand Up @@ -35,6 +36,18 @@ describe('useTransition', () => {
expect(rendered).toEqual([false])
})

it('assign controllers to provided "ref"', async () => {
const ref = new SpringRef()
const props = {
ref,
}
const children = [<div />, <div />, <div />]

update(children, props)

expect(ref.current).toHaveLength(3)
})

describe('when "leave" is an array', () => {
it('unmounts after leave', async () => {
const props = {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/hooks/useTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export function useTransition(
// The payload is used to update the spring props once the current render is committed.
const payload: ControllerUpdate<UnknownProps> = {
...defaultProps,
ref: props.ref,
delay: (delay += trail),
// This prevents implied resets.
reset: false,
Expand Down