Skip to content

Instantly share code, notes, and snippets.

@Ebrahim-Ramadan
Created September 14, 2023 17:31
Show Gist options
  • Save Ebrahim-Ramadan/69c8f15c36ccf453d518d9fc77c6da9a to your computer and use it in GitHub Desktop.
Save Ebrahim-Ramadan/69c8f15c36ccf453d518d9fc77c6da9a to your computer and use it in GitHub Desktop.
Terminal-like loading Animation
// TerminalloadingAnimation.js
import React, { useState, useEffect } from 'react';
const TerminalloadingAnimation = () => {
const [loadingAnimation, setLoadingAnimation] = useState('|');
useEffect(() => {
const animationCharacters = ['|', '/', '-'];
const updateLoadingAnimation = () => {
setLoadingAnimation((prevChar) => {
const currentIndex = animationCharacters.indexOf(prevChar);
const nextIndex = (currentIndex + 1) % animationCharacters.length;
return animationCharacters[nextIndex];
});
};
const animationInterval = setInterval(updateLoadingAnimation, 250);
return () => clearInterval(animationInterval);
}, []);
return <span>{loadingAnimation}</span>;
};
export default TerminalloadingAnimation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment