Created
September 14, 2023 17:31
-
-
Save Ebrahim-Ramadan/69c8f15c36ccf453d518d9fc77c6da9a to your computer and use it in GitHub Desktop.
Terminal-like loading Animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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