You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			16 lines
		
	
	
		
			346 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			16 lines
		
	
	
		
			346 B
		
	
	
	
		
			TypeScript
		
	
| import { useState } from 'react';
 | |
| import useInterval from 'react-use/lib/useInterval';
 | |
| 
 | |
| export function useModulo(loopBackAt: number, delay: number) {
 | |
|   const [count, setCount] = useState(0);
 | |
| 
 | |
|   useInterval(() => {
 | |
|     if (count >= loopBackAt) {
 | |
|       setCount(0);
 | |
|     } else {
 | |
|       setCount(count + 1);
 | |
|     }
 | |
|   }, delay);
 | |
|   return { count };
 | |
| }
 |