Skip to content

Instantly share code, notes, and snippets.

@SOliv1
Created July 24, 2022 18:05
Show Gist options
  • Save SOliv1/503a0cb1a749797581ecba584821b560 to your computer and use it in GitHub Desktop.
Save SOliv1/503a0cb1a749797581ecba584821b560 to your computer and use it in GitHub Desktop.
https://gist.github.com/4e42075b9544483d5bd3afca31dd9ee3
@SOliv1
Copy link
Author

SOliv1 commented Jul 24, 2022

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

@SOliv1
Copy link
Author

SOliv1 commented Jul 24, 2022

view here

['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