0
我試圖讓componentWillLeave
被調用,我沒有運氣。 componentWillAppear
被調用,但我無法讓前者調用。我見過的大多數回覆都要求確保回調函數被調用,我正在這樣做。如果這有所作爲,我也使用React路由器。任何幫助將不勝感激。react-transition-group生命週期方法componentWillLeave不被調用
import React, { Component } from 'react';
import { TweenMax } from 'gsap';
import PropTypes from 'prop-types';
import { Animated } from '../../components/common/Animated';
import NavButton from '../../components/navButton/NavButton';
import './Team.scss';
class Team extends Component {
componentDidMount() {
this.el = this.refs.container;
}
componentWillAppear(callback) {
TweenMax.set(this.el, { x: '100%' });
TweenMax.to(this.el, 1, { x: '0%' });
callback();
}
componentWillLeave(callback) {
TweenMax.to(this.el, 1, { x: '-100%', onComplete: callback });
}
render() {
const { match } = this.props;
return (
<div ref="container" className="teamContainer">
<NavButton
title={'To Interactive'}
route={`/${match.params.monster}/interactive`}
/>
</div>
);
}
}
Team.propTypes = {
match: PropTypes.shape({
pathname: PropTypes.shape({
monster: PropTypes.number.isRequired,
}),
}),
};
Team.defaultProps = {
match: {
pathname: {
monster: -1,
},
},
};
export default Animated(Team);