Created
July 24, 2022 18:05
-
-
Save SOliv1/503a0cb1a749797581ecba584821b560 to your computer and use it in GitHub Desktop.
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
https://gist.github.com/4e42075b9544483d5bd3afca31dd9ee3 |
['Aquamarine', 'BlueViolet', 'Chartreuse', 'CornflowerBlue', 'Thistle', 'SpringGreen', 'SaddleBrown', 'PapayaWhip', 'MistyRose'];
export default function ColorPicker() {
const [color, setColor] = useState("Tomato");
const divStyle = {backgroundColor: color};
return (
Selected color: {color}
{colorNames.map((colorName)=>(
<button
onClick={() => setColor(colorName)}
key={colorName}>
{colorName}
))}
);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update Function Component State
Let’s get started with the State Hook, the most common Hook used for building React components. The State Hook is a named export from the React library, so we import it like this:
Color Picker