Created
February 22, 2020 00:53
-
-
Save kognise/34feafb5abc9106d84471c537672503d to your computer and use it in GitHub Desktop.
This file contains 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
function Expletives({ children }) { | |
let [letters, setLetters] = useState(children); | |
useEffect(() => { | |
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) { | |
return; | |
} | |
let interval = setInterval(() => { | |
let newLetters = children.split("").map((letter, index) => { | |
let color = Math.round(Math.random() * 360); | |
let char = | |
Math.random() < 0.75 ? letter.toLowerCase() : letter.toUpperCase(); | |
return ( | |
<span style={{ color: `hsl(${color}, 30%, 50%)` }} key={index}> | |
{char} | |
</span> | |
); | |
}) | |
setLetters(newLetters); | |
}); | |
return () => clearInterval(interval); | |
}, []); | |
return <b>{letters}</b>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment