[英]React “react-transition-group” doesn't work
I'm migrating my project to the last version of React, I a see that ReactCSSTransitionGroup
are deprecated ... So I using recomended package by React devs. 我正在将项目迁移到React的最新版本,我发现
ReactCSSTransitionGroup
已被弃用 ...因此,我使用了React开发人员推荐的软件包 。 When I was using ReactCSSTransitionGroup
the animation works correctly when components render, but with this package the component doesn't work and doesn't animate. 当我使用
ReactCSSTransitionGroup
,动画在组件渲染时可以正常工作,但是使用此程序包,组件将无法工作且无法动画。
I make a simple example to test, but doesn't work... Whats wrong? 我举了一个简单的示例进行测试,但无法正常工作。
React Code: 反应代码:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
class App extends Component {
render() {
return (
<CSSTransitionGroup
transitionName="example"
transitionAppear={true}
transitionAppearTimeout={3000}
transitionEnter={true}
transitionEnterTimeout={3000}
transitionLeave={false}>
<div id="container">
Animation test
</div>
</CSSTransitionGroup>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('app')
);
CSS Code: CSS代码:
.example-enter {
opacity: 0.01;
border: 1px solid red;
}
.example-enter.example-enter-active {
opacity: 1;
transition: all 2s ease 0s;
border: 1px solid orange;
}
.example-leave {
opacity: 1;
border: 1px solid green;
}
.example-leave.example-leave-active {
opacity: 0.01;
transition: all 3s ease 0s;
border: 1px solid blue;
}
from the doc : "You must provide the key attribute for all children of CSSTransitionGroup, even when only rendering a single item. This is how React will determine which children have entered, left, or stayed." 来自doc:“即使仅渲染单个项目,也必须为CSSTransitionGroup的所有子项提供键属性。这是React将确定哪些子项已进入,离开或停留的方式。”
Moreover, you should also check your css class name and adding "appear" prefix if you want animation during initial mount: 此外,如果要在初始安装过程中进行动画处理,还应该检查CSS类名称并添加“ appear”前缀。
.example-appear {
opacity: 0.01;
border: 1px solid red;
}
.example-appear.example-appear-active {
opacity: 1;
transition: all 2s ease 0s;
border: 1px solid orange;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.