Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Im new to coding and React. Please bare with me

I want to change the color of the ‘left–innerTopBox’ whenever the changes.
I believe im missing a handleChange function and an onChange. THANKS for you help.

import "./App.css";
import { useState } from "react";

function App() {
  const [color, setColor] = useState({
    color1: "#fff",
  });
  return (
    <>
      <div className="box--control">
        <div className="big--leftBox">
          left box
          <div className="left--innerTopBox" value={color.color1}>
            color here
          </div>
          <div className="left--innerBottomBox">code here</div>
        </div>

        <div className="big--rightBox">
          right box
          <div className="inputs">
            Color 1
            <input
              type="color"
              style={{ marginLeft: 10 }}
              value={color.color1}
            />
          </div>
          <div className="inputs">
            Color 2<input type="color" style={{ marginLeft: 10 }} />
          </div>
        </div>
      </div>
    </>
  );
}
export default App;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try something like this:

import "./App.css";
import { useState} from "react";

function App() {
  const [color, setColor] = useState({
    color1: "#fff",
  });

  const handleChange = (e) => {
    setColor({ ...color, color1:  e.target.value });
  };

  return (
    <>
      <div className="box--control">
        <div className="big--leftBox">
          left box
          <div
            className="left--innerTopBox"
            style={{ backgroundColor: color.color1 }}
          >
            color here
          </div>
          <div className="left--innerBottomBox">code here</div>
        </div>

        <div className="big--rightBox">
          right box
          <div className="inputs">
            Color 1
            <input
              type="color"
              style={{ marginLeft: 10 }}
              value={color.color1}
              onChange={handleChange}
            />
          </div>
          <div className="inputs">
            Color 2<input type="color" style={{ marginLeft: 10 }} />
          </div>
        </div>
      </div>
    </>
  );
}

export default App;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading