Pause animation with setTimeOut

Asked

Viewed 49 times

0

I am using the Lottie library in React Activate and want to animate an object and after 2.5 seconds pause the animation, but settTimeOut returns me an error. The command anim.pause() works properly out of setTimeOut.

Declaration of animation:

<LottieView
    ref={(animation) => {
       anim = animation;}}
    style={{width: wh * 10, height: wh * 10}}
    source={send}
/>

Picking up the Lottie component reference:

let anim = useRef(null);

Where I call the function:

function Send(){
  anim.play();
  setTimeout(() => { anim.pause() }, 2500);
}

The error: Typeerror: null is not Object (evaluating 'anim.pause')

Can someone help me with that?

1 answer

0

I think you better use:

  let interval = setInterval(() => {
    
  clearInterval(interval);

  }, 1000);

clearInterval for the setInterval.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.