Skip to content

Instantly share code, notes, and snippets.

@DruRly
Last active May 22, 2019 22:58
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 DruRly/b2bc46b5b74ffd06592034876b322b45 to your computer and use it in GitHub Desktop.
Save DruRly/b2bc46b5b74ffd06592034876b322b45 to your computer and use it in GitHub Desktop.
Color Theme Generator (Scooter 1/2)
import React, { useState } from "react"
import "./App.css"
const Color = props => {
return (
<div style={{ backgroundColor: props.color }}>
<h1>{props.color}</h1>
</div>
)
}
const App = () => {
const randomColor = () => `#${(Math.random().toString(16) + "000000").substring(2, 8)}`
const [colors, setColors] = useState([randomColor(), randomColor(), randomColor()])
const changeColors = () => {
setColors([randomColor(), randomColor(), randomColor()])
}
return (
<div className="App">
<button onClick={changeColors}>Change Colors</button>
{ colors.map(color => <Color color={color} />) }
</div>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment