Reactjs react转换组生命周期方法组件将不被调用

Reactjs react转换组生命周期方法组件将不被调用,reactjs,Reactjs,我正在尝试获取组件将离开以获得呼叫,但我没有运气组件将出现被调用,但我无法让前者调用。我看到的大多数回复都要求确保调用回调,我正在这样做。我也在使用React路由器,如果这有区别的话。任何帮助都将不胜感激 import React, { Component } from 'react'; import { TweenMax } from 'gsap'; import PropTypes from 'prop-types'; import { Animated } from '../../com

我正在尝试获取
组件将离开
以获得呼叫,但我没有运气<代码>组件将出现
被调用,但我无法让前者调用。我看到的大多数回复都要求确保调用回调,我正在这样做。我也在使用React路由器,如果这有区别的话。任何帮助都将不胜感激

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);
import React,{Component}来自'React';
从“gsap”导入{TweenMax};
从“道具类型”导入道具类型;
从“../../components/common/Animated”导入{Animated};
从“../../components/NavButton/NavButton”导入NavButton;
导入“/Team.scss”;
类团队扩展组件{
componentDidMount(){
this.el=this.refs.container;
}
组件将出现(回调){
TweenMax.set(this.el,{x:'100%});
TweenMax.to(this.el,1,{x:'0%});
回调();
}
组件将离开(回调){
TweenMax.to(this.el,1,{x:'-100%,onComplete:callback});
}
render(){
const{match}=this.props;
返回(
);
}
}
Team.propTypes={
匹配:PropTypes.shape({
路径名:PropTypes.shape({
怪物:需要PropTypes.number.isRequired,
}),
}),
};
Team.defaultProps={
匹配:{
路径名:{
怪物:-1,
},
},
};
导出默认动画(团队);

我没有在react路由器上尝试过这一点,但使用了类似的路由器方法。我使用TransitionGroup v1.x使其正常工作,并确保我的活动子组件

  • 反应元素
  • 有自己独特的钥匙
  • 注:

    使用CSSTransitionGroup时,当转换结束时,组件无法得到通知,也无法执行任何更复杂的动画逻辑。如果想要更细粒度的控制,可以使用较低级别的TransitionGroup API,它提供了进行自定义转换所需的挂钩