Build a Color Picker App - Build a Color Picker App

Tell us what’s happening:

I can’t work out how to pass the new color to the color-picker-container

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>Color Picker</title>
    <link rel="stylesheet" href="styles.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.3.1/umd/react.development.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.3.1/umd/react-dom.development.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.26.5/babel.min.js"></script>
    <script
      data-plugins="transform-modules-umd"
      type="text/babel"
      src="index.jsx"
    ></script>
</head>

<body>
    <div id="root"></div>
    <script
      data-plugins="transform-modules-umd"
      type="text/babel"
      data-presets="react"
      data-type="module"
    >
      import { ColorPicker } from './index.jsx';
      ReactDOM.createRoot(document.getElementById('root')).render(<ColorPicker />);
    </script>
</body>

</html>
/* file: styles.css */
body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, sans-serif;
}

#color-picker-container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background-color: #ffffff;
}

input[type="color"] {
    position: absolute;
    margin-top: 50px;
    height: 40px;
}
/* file: index.jsx */
const { useState } = React;

export const ColorPicker = ({color}) => {

  const handleChange = (e) => {
    setColor(e.target.value);
  };

  const [colorState, setColor] = useState("#ffffff");

  return (
    <div id="color-picker-container" style={{backgroundColor: "white"}}>
      <input  type="color" id="color-input" onChange={handleChange} style={{backgroundColor: color}}></input>
    </div>
  );
};

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Build a Color Picker App - Build a Color Picker App

You will need to assign it to a variable and update the variable

Kind of like you are doing with the color picker.

Keep in mind you have create a variable called colorState. Do you use it?

I think I’m passing the new color to the container now, but I still can’t pass 12 and 13- colorInput having a value of #ffffff initially and its colour being managed by useState (even though I think it is)

Please share your updated code

const { useState } = React;

export const ColorPicker = () => {

  const handleChange = (e) => {
    setColor(e.target.value);
  };

  const [colorState, setColor] = useState("#ffffff");

  return (
    <div id="color-picker-container" style={{backgroundColor: colorState  || "white"}}>
      <input  type="color" id="color-input" onChange={handleChange} style={{color: colorState}}></input>
    </div>
  );
};

Worked it out already.