Skip to content

Instantly share code, notes, and snippets.

@kognise
Created February 22, 2020 00:53
Show Gist options
  • Save kognise/34feafb5abc9106d84471c537672503d to your computer and use it in GitHub Desktop.
Save kognise/34feafb5abc9106d84471c537672503d to your computer and use it in GitHub Desktop.
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