[英]Where to put callback function in react-transition-group
I want to run a process only after transition has ended. 我只想在转换结束后才运行一个进程。
Here the docs say: 这里的文档说:
addEndListener
addEndListener
Add a custom transition end trigger.
添加自定义过渡结束触发器。 Called with the transitioning DOM node and a done callback.
通过过渡的DOM节点和完成的回调调用。 Allows for more fine grained transition end logic.
允许使用更细粒度的过渡逻辑。 Note: Timeouts are still used as a fallback if provided.
注意:超时(如果提供)仍用作备用。
addEndListener={(node, done) => { // use the css transitionend event to mark the finish of a transition node.addEventListener('transitionend', done, false); }}
So I use it like this: 所以我这样使用它:
<Transition
addEndListener={(node, done) => {node.addEventListener('transitionend', done, false);}}>
<MyComponent />
</Transition>
The problem is I don't understand where to put my function to be executed after the transition ended. 问题是在过渡结束后,我不知道将函数放在哪里执行。
If this is my function: 如果这是我的职能:
function abc() {
// blah
// blah
//blah
}
Where can I put it? 我可以放在哪里? Should I put it in the place of
done
? 我应该把它放在
done
的地方吗?
You can use addEndListener
, or even onExited
and onEntered
callbacks. 您可以使用
addEndListener
,甚至onExited
和onEntered
回调。
With addEndListener
: 使用
addEndListener
:
function abc() {
// blah
// blah
//blah
}
... // some code
<Transition
addEndListener={(node, done) => {node.addEventListener('transitionend',(e) => {
abc(e);
done(e);
}, false);}}>
<MyComponent />
</Transition>
With onEntered
and onExited
: 随着
onEntered
和onExited
:
<Transition
onEntered={abc} onExited={abc}>
<MyComponent />
</Transition>
An important thing of the second example: check the moment, when you want to get your callback called. 第二个示例的重要事项:检查何时要调用回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.