-
-
Save codecademydev/7521d7bf13d6191b55c9ce0398885df5 to your computer and use it in GitHub Desktop.
Codecademy export
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
import React, { useState } from 'react'; | |
const colorNames = ['Aquamarine', 'BlueViolet', 'Chartreuse', 'CornflowerBlue', 'Thistle', 'SpringGreen', 'SaddleBrown', 'PapayaWhip', 'MistyRose']; | |
export default function ColorPicker() { | |
const [color, setColor] = useState("Tomato"); | |
const divStyle = {backgroundColor: color}; | |
return ( | |
<div style={divStyle}> | |
<p>Selected color: {color}</p> | |
{colorNames.map((colorName)=>( | |
<button | |
onClick={() => setColor(colorName)} | |
key={colorName}> | |
{colorName} | |
</button> | |
))} | |
</div> | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment