ReactCSSTransitionGroup或{CSSTransition,TransitionGroup}

时间:2018-05-31 11:43:05

标签: reactjs animation css-transitions reactcsstransitiongroup react-transition-group

我对ReactCSSTransitionGroup有点困惑。阅读文档

在使用的示例中:ReactCSSTransitionGroup和单个CSSTransition,在列表示例中{CSSTransition,TransitionGroup}

所以他们都做同样的事情(动画),但ReactCSSTransitionGroup看起来像这样

所有来自doc例子

 render() {
  return (
    <ReactCSSTransitionGroup
      transitionName="example"
      transitionAppear={true}
      transitionAppearTimeout={500}
      transitionEnter={false}
      transitionLeave={false}>
      <h1>Fading at Initial Mount</h1>
    </ReactCSSTransitionGroup>
  );
}

单个CSSTransition

<CSSTransition
   in={showValidationMessage}
   timeout={300}
   classNames="message"
   unmountOnExit
   onExited={() => {
     this.setState({
     showValidationButton: true,});}}
  >
          *some code*        
</CSSTransition>

{CSSTransition,TransitionGroup} - 像这样

<TransitionGroup className="todo-list">
   {items.map(({ id, text }) => (
      <CSSTransition key={id}  timeout={500} classNames="fade">
         <ListGroupItem>
           *Some code*
         </ListGroupItem>
     </CSSTransition>
  ))}
</TransitionGroup>

那么当我应该/更好地使用ReactCSSTransitionGroup,单个CSSTransition或{CSSTransition,TransitionGroup}?

0 个答案:

没有答案