【发布时间】:2017-02-08 23:23:12
【问题描述】:
我在我的项目中使用 react motion 来制作动画。我通过维护状态解决了每次 prop 更改时渲染动画的问题。
const {animation} = this.state;
if (animation) {
return (
// updates state upon animatioon to false
<Animator rest={this.rest}>
{this.getContent()}
</Animator>
);
}
return this.getContent();
我有一个回调,它将在动画完成后改变我的状态。这解决了除了动画时道具变化之外的所有问题。
假设我的动画发生了 2 秒,然后触发回调,但如果动画在中间像 1 秒并且我的道具发生变化,那么我的动画再次从头开始。
我不想使用shouldComponentUpdate,因为它会停止更新视图。
那么这种情况通常是如何处理的。用shouldComponentUpdate可以吗。有没有更好的选择?
提前致谢。
【问题讨论】:
-
您是否使用
componentWillReceiveProps来处理道具更改?还是直接绑定到道具? -
@BradBumbalough 上面的代码在我的渲染函数中,当我的道具改变时渲染
标签: javascript animation reactjs web browser