Answers for "onclick toggle class react"

0

onclick toggle class react

import React, { useState } from "react";import "./styles.css";

export default function App() {
  const [isActive, setActive] = useState("false");
  const handleToggle = () => {
    setActive(!isActive);  };
  return (
    <div className={isActive ? "app" : null}>      <h1>Hello react</h1>
      <button onClick={handleToggle}>Toggle class</button>    </div>
  );
}
Posted by: Guest on August-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language