The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/stories/hooks/useAutoSequence.ts

15 lines
375 B

import { useEffect, useState } from 'react';
export const useAutoSequence = <P>(sequence: readonly P[], delay = 700): P => {
const [index, setIndex] = useState(0);
useEffect(() => {
const timer = setInterval(() => setIndex((index) => index + 1), delay);
return (): void => {
clearInterval(timer);
};
}, [delay]);
return sequence[index % sequence.length];
};