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.
		
		
		
		
		
			
		
			
				
	
	
		
			17 lines
		
	
	
		
			395 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			17 lines
		
	
	
		
			395 B
		
	
	
	
		
			TypeScript
		
	
| import React from 'react';
 | |
| // tslint:disable-next-line: no-submodule-imports
 | |
| import useInterval from 'react-use/lib/useInterval';
 | |
| 
 | |
| export function useModulo(loopBackAt: number, delay: number) {
 | |
|   const [count, setCount] = React.useState(0);
 | |
| 
 | |
|   useInterval(() => {
 | |
|     if (count >= loopBackAt) {
 | |
|       setCount(0);
 | |
|     } else {
 | |
|       setCount(count + 1);
 | |
|     }
 | |
|   }, delay);
 | |
|   return { count };
 | |
| }
 |