首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用react-transition-group生命周期方法componentWillLeave

未调用react-transition-group生命周期方法componentWillLeave
EN

Stack Overflow用户
提问于 2017-06-15 21:56:39
回答 1查看 146关注 0票数 0

我在试着让componentWillLeave打个电话但我没找到。调用了componentWillAppear,但我无法调用前者。我看到的大多数响应都要求确保回调被调用,我就是这么做的。如果有什么不同的话,我也在使用React路由器。任何帮助都将不胜感激。

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2017-09-28 01:33:40

我还没有在react路由器上尝试过,但使用了类似的路由器方法。我使用TransitionGroup v1.x让它工作,并确保我的活动子组件是

  1. a react element
  2. 有自己的唯一键

https://github.com/reactjs/react-transition-group/tree/v1-stable

备注:

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44569424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档