#app
View Compiled
*
box-sizing border-box
body
margin 0
padding 0
transition background .25s ease
#app
align-items center
display flex
flex-direction column
justify-content center
min-height 100vh
select
cursor pointer
font-size 1.5rem
h1
color #fff
View Compiled
const { React, ReactDOM } = window
const { useEffect, useState, Fragment } = React
const { render } = ReactDOM
const rootNode = document.getElementById('app')
const colors = {
Sea: '#a2ccb6',
Sand: '#fceeb5',
Peach: '#ee786e',
}
const App = () => {
const [color, setColor] = useState(colors.Sea)
useEffect(
() => {
document.body.style.background = color
},
[color]
)
return (
<Fragment>
<select value={color} onChange={e => setColor(e.target.value)}>
{Object.entries(colors).map(([name, value]) => (
<option key={`color--${name}`} value={value}>
{name}
</option>
))}
</select>
<h1>{color}</h1>
</Fragment>
)
}
ReactDOM.render(<App />, rootNode)
View Compiled
This Pen doesn't use any external CSS resources.