[英]Reactjs CSSTransition Component props in TransitionGroup
I'm currently looking into animate a set of divs.我目前正在研究为一组 div 设置动画。 I came across this example and it is exactly what i need.
我遇到了这个例子,这正是我所需要的。 As im still a noobie in react, i dont really understand how the props are being fed throw the
<Fade>
component, inparticular the Fade params ({ children, ...props })
.由于我仍然是反应中的菜鸟,我真的不明白道具是如何被抛出
<Fade>
组件的,特别是 Fade 参数({ children, ...props })
。 If someone can shed some light that will be greatly appreciated it..如果有人能提供一些启发,将不胜感激..
Here is the snippet of Fade
这是
Fade
的片段
const Fade = ({ children, ...props }) => (
<CSSTransition
{...props}
timeout={1000}
classNames="fade"
>
{children}
</CSSTransition>
);
Here is the usage:这是用法:
<div className='container'>
<TransitionGroup className='todo-list'>
{this.state.items.map((item, i) => (
<Fade key={item}>
<div>
{`${item} `}
<button onClick={() => this.handleRemove(i)}>
×
</button>
</div>
</Fade>
))}
</TransitionGroup>
<button onClick={() => this.handleAdd()}>Add Item</button>
</div>
The props are fed to Fade using Destructuring Assignment For example使用解构赋值将道具馈送到 Fade 例如
const {children, ...props} = {children: 0, propsA: 1, propsB: 2}
console.log(children); // 0
console.log(props); // {propsA: 1, propsB: 2}
...
represents Rest & Spread operators ...
代表Rest和扩展运算符
const Fade = ({ children, ...props }) => (); // This ... is Rest Operator
<CSSTransition {...props}/> // This ... is Spread Operator
Here, props.children is those wrapped by Fade
, which is:这里, props.children是被
Fade
包裹的那些,即:
<div>
{`${item} `}
<button onClick={() => this.handleRemove(i)}>
×
</button>
</div>
Fade
is like to wrap things using CSSTransition
and conceal some props. Fade
就像是用CSSTransition
包裹东西并隐藏一些道具。
You can actually rewrite as the follows:您实际上可以重写如下:
<div className='container'>
<TransitionGroup className='todo-list'>
{this.state.items.map((item, i) => (
<CSSTransition key={item} timeout={1000} classNames="fade">
<div>
{`${item} `}
<button onClick={() => this.handleRemove(i)}>
×
</button>
</div>
</CSSTransition>
))}
</TransitionGroup>
<button onClick={() => this.handleAdd()}>Add Item</button>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.