React.js 我对下面的 React.js 代码有疑问。我正在尝试使用“React-router.Link”在页面转换之前设置动画。和 ReactCSSTransitionGroup。
版本反应:'15.2.1' react-addons-css-transition-group:'15.2' react-router:'2.6.0'
我想得到生命周期事件,所以我可以使用 JS 而不是 CSS。如果你知道正确的做法,请告诉我。谢谢你。
例如)componentWillLeave 等...
PS 我试过这段代码,但 componentWillLeave 没有触发。
var React = require("react");
var ReactRouter = require("react-router");
var CSSTransitionGroup = require('react-addons-css-transition-group');
var Link = ReactRouter.Link;
var Test = React.createClass({
componentWillLeave: function(callback) {
console.log("component will leave");
$(this.getDOMNode()).hide(duration, callback);
},
render: function() {
return (
<div id="index">
<CSSTransitionGroup transitionName="example" transitionAppear={true} transitionLeave={true} transitionAppearTimeout={3000} transitionLeaveTimeout={3000}>
<Link to="/" key="toIndex">Index</Link>
<Link to="contact" key="toContact">Contact</Link>
</CSSTransitionGroup>
</div>
)
}
});