【发布时间】:2016-09-28 01:19:38
【问题描述】:
我仍然是 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,但 docs 并没有明确说明我应该何时使用它。
那么,一个人能做什么而另一个人不能?有人可以用更好的例子向我解释一下吗?
【问题讨论】:
-
youtube.com/watch?v=hEGg-3pIHlE 这个人正在展示他如何使用 cloneElement。看看这里的一些例子
标签: reactjs