import React, { useEffect, useRef } from "react"; import { Progress } from "theme-ui"; function LoadingBar({ isLoading, loadingProgressRef }) { const requestRef = useRef(); const progressBarRef = useRef(); // Use an animation frame to update the progress bar // This bypasses react allowing the animation to be smooth useEffect(() => { function animate() { if (!isLoading) { return; } requestRef.current = requestAnimationFrame(animate); if (progressBarRef.current) { progressBarRef.current.value = loadingProgressRef.current; } } requestRef.current = requestAnimationFrame(animate); return () => { cancelAnimationFrame(requestRef.current); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoading]); return ( ); } export default LoadingBar;