简体   繁体   English

未安装组件上的成帧器运动退出 animation

[英]Framer-motion exit animation on unmounted component

I'm trying to play an animation on dismounting of my component with exit attribute, but it doesn't work despite the presence of !我正在尝试在使用 exit 属性卸载我的组件时播放 animation,但尽管存在 !

The input animation works fine but not the output one !输入 animation 工作正常,但不是 output 一个!

I guess I'm mismanaging the dismounting of my description which is displayed if the props data.show is true, boolean that I change at the click on the project, in short if someone can point me...我想我对我的描述的卸载管理不善,如果道具 data.show 为真,boolean 我在点击项目时更改,简而言之,如果有人可以指出我...

codesandbox 密码箱

Thanks in advance提前致谢

There are quite a few issues to cover in your code and suggest you first understand what triggers re-rendering in React.你的代码中有很多问题需要解决,建议你首先了解什么会触发 React 中re-rendering

By creating a new uuid key every time you change prop data, you are breaking the ability for React to know which components need to be rendered again so it re-renders them all - so it's always a new instance on AnimatePresence and no way for AnimatePresence to know there has been a change to the key or a change in mounting.通过在每次更改道具数据时创建一个新的 uuid 键,您破坏了 React 知道哪些组件需要再次渲染以便重新渲染它们的能力 - 所以它始终是AnimatePresence上的一个新实例,而AnimatePresence没有办法要知道钥匙发生了变化或安装发生了变化。 Also make use of useCallback hooks when passing in functions to child components to avoid re-renders.在将函数传递给子组件时,还要使用useCallback钩子以避免重新渲染。

Move the state up to the parent, update the card key to a consistent value between renders, and don't update the entire props data just to expand/collapse.将 state 向上移动到父级,将卡键更新为渲染之间的一致值,不要为了展开/折叠而更新整个道具数据。

See the updated sandbox查看更新的沙箱

I suggest that you don't animate multiple items inline within the same space like this as you will always have the remaining boxes jump a little, but that is another topic.我建议您不要像这样在同一空间内为多个内联项目设置动画,因为您总是会让剩余的框跳一点,但这是另一个话题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM