Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React spring loop won't run with delay

Tags:

react-spring

I'm using these styles with react spring, and after it runs one time, it won't run anymore, if I remove the delay it works fine, why is that?

const styles = useSpring({
  loop: true,
  to: [
    { opacity: 0, color: '#53317e' },
    { opacity: 1, color: 'white' },
  ],
  from: { opacity: 1, color: 'white' },
  delay: 1000,
})
like image 630
Alexander Avatar asked May 21 '26 14:05

Alexander


1 Answers

lot of time gone but I had same issue.

To fix it, instead of using

const styles = useSpring({ 
   loop: true,
   delay: 2000,
   from: {...},
   to: [{...}, {...}, ...]
 });

I used syntax with passing function instead of object

  const [styles, api] = useSpring(() => ({ ... }) )

And then delay prop stops disabling my loop

like image 127
Norbert Kulus Avatar answered Jun 05 '26 01:06

Norbert Kulus