File tree 1 file changed +19
-2
lines changed
1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import { useEffect } from "react";
36
36
import { useAnimation } from " react-animatable" ;
37
37
38
38
export const App = () => {
39
+ // Define your animation in WAAPI way
39
40
const animate = useAnimation (
40
41
[
41
42
{ fill: " red" , fontSize: " 24px" },
@@ -50,13 +51,29 @@ export const App = () => {
50
51
);
51
52
52
53
useEffect (() => {
54
+ // And play it!
53
55
animate .play ();
54
56
}, []);
55
57
56
58
return (
57
- <svg width = { 600 } height = { 400 } viewBox = " 0 0 600 400" >
59
+ <svg
60
+ width = { 600 }
61
+ height = { 400 }
62
+ viewBox = " 0 0 600 400"
63
+ onClick = {
64
+ // The return value of useAnimation and its methods are memoized
65
+ animate .pause
66
+ }
67
+ >
58
68
<g transform = " translate(50, 50)" >
59
- <text ref = { animate .ref } >Hello world</text >
69
+ <text
70
+ ref = {
71
+ // You have to pass ref to element you want to control
72
+ animate .ref
73
+ }
74
+ >
75
+ Hello world
76
+ </text >
60
77
</g >
61
78
</svg >
62
79
);
You can’t perform that action at this time.
0 commit comments