score:4

Accepted answer

try this

  function App() {
  const [color,setColor]=useState('red');
  const [textColor,setTextColor]=useState('white');
  return (
    <div className="App">
      <button style={{background:color,color:textColor}} className='btn btn-primary' onClick={()=>{setColor("black");setTextColor('red')}}>Click here</button>
    </div>
  );
}

export default App;

OR check link : https://stackblitz.com/edit/react-x7mevv

score:0

App.js

function App() {
  const [toggle,setToggle] = React.useState(false);
  const toggleIt =()=>{
    setToggle(!toggle)
  }
  return (
    <div className="App">
    <button onClick={toggleIt}>{toggle?'Hide':'Show'}</button>
     <div className={toggle&&'body-color'}>
      Body
     </div>
    </div>
  );
}

class in App.css

.body-color{
  background: coral;
  height:100vh;
}

Related Query

More Query from same tag