我仍然是 React 的菜鸟,在互联网上的许多示例中,我看到渲染子元素的这种变化让我感到困惑。通常我看到这个:
class Users extends React.Component {
  render() {
    return (
      <div>
        <h2>Users</h2>
        {this.props.children}
      </div>
    )
  }
}
但后来我看到一个这样的例子:
<ReactCSSTransitionGroup
     component="div"
     transitionName="example"
     transitionEnterTimeout={500}
     transitionLeaveTimeout={500}
     >
     {React.cloneElement(this.props.children, {
       key: this.props.location.pathname
      })}
</ReactCSSTransitionGroup>
现在我理解了 api,但是文档并没有明确说明我应该何时使用它。
那么一个人能做什么而另一个人不能呢?有人可以用更好的例子向我解释这一点吗?