Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created July 24, 2022 18:09
Show Gist options
  • Save codecademydev/7521d7bf13d6191b55c9ce0398885df5 to your computer and use it in GitHub Desktop.
Save codecademydev/7521d7bf13d6191b55c9ce0398885df5 to your computer and use it in GitHub Desktop.
Codecademy export
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