useEffect, 注意,useEffect 中, return 是为了cleanup, 即调用 Tween 实例的 kill 方法,否则会报错: Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
如上图,
integer
整数和float
是有滚动动画的,我喜欢用最少,最简洁的代码实现功能,这个component
比较轻,所以使用了React 16.8
增加的 HooksFeature
,直接上代码:一、整数动画
return
的是一个Tween
实例,Tween
实例是需要 [kill](https://greensock.com/docs/v3/GSAP/Tween/kill()) 掉的,否则浪费资源,就像setTimeout
一样useEffect
中, return 是为了cleanup, 即调用Tween
实例的kill
方法,否则会报错:Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
二、浮点数动画