Last active
February 22, 2020 16:42
-
-
Save ryanflorence/28a8d96e39ed3cbb661c5e28a48fadac 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 [, forceUpdate] = useState(); | |
let mounted = useRef(false); | |
useEffect(() => { | |
mounted.current = true; | |
// don't want to cause any seizures. | |
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) { | |
return; | |
} | |
let timeout = setTimeout(() => { | |
forceUpdate({}); | |
}, 200); | |
return () => clearTimeout(timeout); | |
}); | |
let letters = | |
// don't do these tricks intially so server/client hydration matches | |
mounted.current === false | |
? children | |
: 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> | |
); | |
}); | |
return <b>{letters}</b>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice thing watching for reduced motion