Skip to content

Instantly share code, notes, and snippets.

@KyleAMathews
Created April 24, 2020 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleAMathews/70103d56afb44f1a56f01d68962e8a77 to your computer and use it in GitHub Desktop.
Save KyleAMathews/70103d56afb44f1a56f01d68962e8a77 to your computer and use it in GitHub Desktop.

Hi from MDX-landia

Click the diagram to regenerate the colors.

export const RandomColors = ({ count = 1000 }) => { const [els, setEls] = React.useState([]) const randomHexColor = () => { return '#' + ('000000' + Math.floor(Math.random()*16777215).toString(16)).slice(-6) } const regenEls = () => { const newEls = [] for (let i = 0; i < count; i++) { newEls.push(<div style={{ height: 16, width: 16, backgroundColor: randomHexColor() }} />) } setEls(newEls) } React.useEffect(() => regenEls(), []) return ( <div onClick={regenEls} style={{ display: 'flex', flexWrap: 'wrap', cursor: 'pointer' }} > {els} ) }

yeah!

The color component is taken from the blog post of MDX creator John Otander exploring randomness and color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment