score:0

in the function buttontwobackgroundcolor you set setbuttontwo to a object. it should be a string.

  const buttontwobackgroundcolor = () => {
    setbuttontwo("red")
  }

score:0

you are trying to set state to be an object when you have defined the defualt state as a string.

update the default state to an object and then access properties like this:

    import react, { usestate } from "react";
import { button } from "antd";
import "./styles.css";

export default function app() {
 

     const [buttonone, setbuttonone] = usestate("red");
    
      const [buttontwo, setbuttontwo] = usestate({backgroundcolor: "blue", border: "blue"});
    
      const buttontwobackgroundcolor = () => {
       setbuttontwo(prevstate => ({
        ...prevstate,
        backgroundcolor: 'blue',
        border: 'red'
     }));
      };
      return (
        <div>
          <button
            style={{ backgroundcolor: buttonone, border: buttonone }}
            classname="one"
            type="primary"
          >
            first
          </button>
          <button
            style={{ backgroundcolor: buttontwo.backgroundcolor, border: buttontwo.border }}
            onclick={buttontwobackgroundcolor}
            classname="two"
            type="primary"
          >
            second
          </button>
        </div>
      );
    }

score:0

change
onclick={buttontwobackgroundcolor}
to
onclick={setbuttontwo("red")}

you are using usestate as string at initialization and assigning an object in function below, which is not proper way!


Related Query

More Query from same tag