最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - why is react-addons-css-transition-group not working here? - Stack Overflow

programmeradmin2浏览0评论
import CSSTransitionGroup from 'react-addons-css-transition-group' ; 

class VariableDefinitions extends Component {

  render() {
    const { idToVarStates } = this.props;

    const varHtmlList = Object.keys(idToVarStates).map(id => {
      return (
        <CSSTransitionGroup
        transitionEnterTimeout={1000} 
        transitionLeaveTimeout={1000}
        transitionName="fade"
        key={id}
         >
            <VariableDefine id={id} key={id} {...this.props} />
        </CSSTransitionGroup>
      );
    })
}}

This is how I am using the transition group . Here are my classes in style.css

.fade-enter{
  opacity: 0;
  height: 0%;
}
.fade-enter-active{
  transition: all 1s ; 
  height: 100%;
  opacity: 1;
}

.fade-leave{
  opacity: 1;
}
.fade-leave-active{
  transition: all 1s ;
  opacity: 0;
}

When I Add elements (VariableDefine) ponents by changing the idToVarStates data , i don't get any animation at all . What is wrong here ? how to fix this ?

import CSSTransitionGroup from 'react-addons-css-transition-group' ; 

class VariableDefinitions extends Component {

  render() {
    const { idToVarStates } = this.props;

    const varHtmlList = Object.keys(idToVarStates).map(id => {
      return (
        <CSSTransitionGroup
        transitionEnterTimeout={1000} 
        transitionLeaveTimeout={1000}
        transitionName="fade"
        key={id}
         >
            <VariableDefine id={id} key={id} {...this.props} />
        </CSSTransitionGroup>
      );
    })
}}

This is how I am using the transition group . Here are my classes in style.css

.fade-enter{
  opacity: 0;
  height: 0%;
}
.fade-enter-active{
  transition: all 1s ; 
  height: 100%;
  opacity: 1;
}

.fade-leave{
  opacity: 1;
}
.fade-leave-active{
  transition: all 1s ;
  opacity: 0;
}

When I Add elements (VariableDefine) ponents by changing the idToVarStates data , i don't get any animation at all . What is wrong here ? how to fix this ?

Share Improve this question edited Dec 5, 2018 at 10:32 Hardik Modha 12.8k3 gold badges39 silver badges42 bronze badges asked Dec 5, 2018 at 9:21 Natesh bhatNatesh bhat 13.3k13 gold badges93 silver badges134 bronze badges 1
  • What do you get in this.props;? – Just code Commented Dec 10, 2018 at 7:51
Add a ment  | 

2 Answers 2

Reset to default 4 +50

The package has been deleted.

First,here is the introduction about react-addons-css-transition-group in npm package.

react-addons-css-transition-group The code in this package has moved. We remend you to use CSSTransitionGroup from react-transition-group instead.

So,the react-addons-css-transition-group package is not remended to use now.It is remended to use react-transition-group.


The page may be crushed.

Second,Object.keys(idToVarStates).map will render too many TransitionGroup.And make the page crush.


Change the CSSTransition to this.

<TransitionGroup className="todo-list">
                {idToVarStates.map(({ id, text }) => (
                    <CSSTransition
                        key={id}
                        timeout={500}
                        classNames="fade"
                    >
                        <VariableDefinition text={text} key={id} filter={this.props.filter} {...this.props}/>
                    </CSSTransition>
                ))}
            </TransitionGroup>

Working code

I create an example for react-transition-group.Here is the result.

And the working code is in here: https://codesandbox.io/s/github/stackOverflow166/variable

Simple answer. The package has been moved. According to the npm page for react-addons-css-transition-group.

The code in this package has moved. We remend you to use CSSTransitionGroup from react-transition-group instead.

Try uninstalling your current package by running npm uninstall react-addons-css-transition-group. Then install the correct package with:

npm i react-transition-group

Change your imports where necessary and wrap your CSSTransitionGroup with <TransitionGroup>. Try that.

You can also walkthrough this (found on the github page of react-transition-group) migration guide to help you along.

Hope this helps.

发布评论

评论列表(0)

  1. 暂无评论