Back

66.66% Statements 6/9
50% Branches 1/2
60% Functions 3/5
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19                  25x 25x 14x     14x 14x      
import { useEffect, useState } from '@wordpress/element';
 
/**
 * Re-render on an interval, so relative times like "a few seconds ago" don't go stale.
 *
 * @param ms      - How often to re-render.
 * @param enabled - Whether there is anything to keep current.
 */
export default function useRerenderEvery( ms: number, enabled: boolean ): void {
	const [ , setTick ] = useState( 0 );
	useEffect( () => {
		Iif ( ! enabled ) {
			return;
		}
		const timer = setInterval( () => setTick( tick => tick + 1 ), ms );
		return () => clearInterval( timer );
	}, [ ms, enabled ] );
}