@@ -8,11 +8,16 @@ import {
8
8
9
9
export default { component : useTransitionAnimation } ;
10
10
11
- const Text = ( { children } : { children : string } ) => {
12
- const prev = useRef ( children ) ;
11
+ const usePrevious = < T , > ( value : T ) => {
12
+ const prev = useRef ( value ) ;
13
13
useEffect ( ( ) => {
14
- prev . current = children ;
15
- } , [ children ] ) ;
14
+ prev . current = value ;
15
+ } , [ value ] ) ;
16
+ return prev . current ;
17
+ } ;
18
+
19
+ const Text = ( { children } : { children : string } ) => {
20
+ const prev = usePrevious ( children ) ;
16
21
17
22
const timing = { duration : 800 , easing : "ease-out" } ;
18
23
const animate = useTransitionAnimation ( {
@@ -32,7 +37,7 @@ const Text = ({ children }: { children: string }) => {
32
37
) ,
33
38
update : useAnimation (
34
39
[ { transform : "rotateX(360deg)" } , { transform : "rotateX(0deg)" } ] ,
35
- children !== prev . current ? timing : undefined
40
+ children !== prev ? timing : undefined
36
41
) ,
37
42
} ) ;
38
43
@@ -76,15 +81,12 @@ const shuffle = <T,>(array: T[]): T[] => {
76
81
77
82
const SvgText = ( { children, i } : { children : string ; i : number } ) => {
78
83
const x = i * 20 ;
79
- const prevX = useRef ( x ) ;
80
- useEffect ( ( ) => {
81
- prevX . current = x ;
82
- } , [ x ] ) ;
84
+ const prevX = usePrevious ( x ) ;
83
85
const timing = { duration : 800 , easing : "ease-in-out" } ;
84
86
const transition = useTransitionAnimation ( {
85
87
update : useAnimation (
86
88
[
87
- { transform : `translateX(${ prevX . current - x } px)` } ,
89
+ { transform : `translateX(${ prevX - x } px)` } ,
88
90
{ transform : `translateX(0px)` } ,
89
91
] ,
90
92
timing
0 commit comments