Skip to content

useTransition component does not unmount #1149

@xuan0123

Description

@xuan0123

🐛 Bug Report

const [canShow, setCanShow] = useState(false)

const trans = useTransition(canShow, {
  from: { opacity: 0 },
  enter: { opacity: 1 },
  leave: { opacity: 0 },
})

const showAndHideQuickly = async () => {
  setCanShow(true)
  await Promise.resolve()
  setCanShow(false)
}

return (
  <>
    <button onClick={showAndHideQuickly}>Show and hide</button>
    {trans((style, item) => item && <animated.div style={style} />)}
  </>
)

If I change the state ( first argument of useTransition ) from false to true, the component will mount. And I change the state back to false quickly, the component will not unmount.

If the from and leave are different, the component will unmount when the state is false.

To Reproduce

https://codesandbox.io/s/react-spring-bug-m23ir?file=/src/App.js

Expected behavior

the mounting and unmounting should follow the state.

Link to repro (highly encouraged)

https://codesandbox.io/s/react-spring-bug-m23ir?file=/src/App.js

Environment

  • react-spring v9.0.0-rc.3
  • react v16.13.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions