@@ -20,34 +20,34 @@ export default function useStateMachineInputs(
20
20
) {
21
21
const [ inputs , setInputs ] = useState < StateMachineInput [ ] > ( [ ] ) ;
22
22
23
- const syncInputs = useCallback ( ( ) => {
24
- if ( ! rive || ! stateMachineName || ! inputNames ) return ;
23
+ useEffect ( ( ) => {
24
+ const syncInputs = ( ) => {
25
+ if ( ! rive || ! stateMachineName || ! inputNames ) return ;
25
26
26
- const riveInputs = rive . stateMachineInputs ( stateMachineName ) ;
27
- if ( ! riveInputs ) return ;
27
+ const riveInputs = rive . stateMachineInputs ( stateMachineName ) ;
28
+ if ( ! riveInputs ) return ;
28
29
29
- // To optimize lookup time from O(n) to O(1) in the following loop
30
- const riveInputLookup = new Map < string , StateMachineInput > (
31
- riveInputs . map ( input => [ input . name , input ] )
32
- ) ;
30
+ // To optimize lookup time from O(n) to O(1) in the following loop
31
+ const riveInputLookup = new Map < string , StateMachineInput > (
32
+ riveInputs . map ( input => [ input . name , input ] )
33
+ ) ;
33
34
34
- setInputs ( ( ) => {
35
- // Iterate over inputNames instead of riveInputs to preserve array order
36
- return inputNames
37
- . filter ( inputName => riveInputLookup . has ( inputName . name ) )
38
- . map ( inputName => {
39
- const riveInput = riveInputLookup . get ( inputName . name ) ! ;
35
+ setInputs ( ( ) => {
36
+ // Iterate over inputNames instead of riveInputs to preserve array order
37
+ return inputNames
38
+ . filter ( inputName => riveInputLookup . has ( inputName . name ) )
39
+ . map ( inputName => {
40
+ const riveInput = riveInputLookup . get ( inputName . name ) ! ;
40
41
41
- if ( inputName . initialValue !== undefined ) {
42
- riveInput . value = inputName . initialValue ;
43
- }
42
+ if ( inputName . initialValue !== undefined ) {
43
+ riveInput . value = inputName . initialValue ;
44
+ }
44
45
45
- return riveInput ;
46
- } ) ;
47
- } ) ;
48
- } , [ inputNames , rive , stateMachineName ] ) ;
46
+ return riveInput ;
47
+ } ) ;
48
+ } ) ;
49
+ } ;
49
50
50
- useEffect ( ( ) => {
51
51
syncInputs ( ) ;
52
52
if ( rive ) {
53
53
rive . on ( EventType . Load , syncInputs ) ;
0 commit comments