Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

toggle classname onclick react

function MyComponent (props) {
  const [isActive, setActive] = useState(false);

  const toggleClass = () => {
    setActive(!isActive);
  };

  return (
    <div 
      className={isActive ? 'your_className': null} 
      onClick={toggleClass} 
    >
      <p>my text</p>
    </div>
   );
}
Comment

Toggle on button click in react js functional component

const [show,setShow]=useState(true)
  return (
    <div className="App">
     {
       show?<h1>Hello World !</h1>:null
     }
<button onClick={()=>setShow(!show)} >Toggle</button> 
    </div>
  );
Comment

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>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongo updatemany query 
Javascript :: chalk nodeks 
Javascript :: discord.js bot mention 
Javascript :: javascript cehck if array is empty 
Javascript :: dynamic event listener jquery 
Javascript :: joi object id validation 
Javascript :: foreach loop javascript 
Javascript :: showing bootstrap modal after a delay 
Javascript :: Fibonacci Recursive in js 
Javascript :: bootstrap 4 navbar-collapse not working angular 
Javascript :: detect logged user wordpress javascript 
Javascript :: javascript localstorage 
Javascript :: js addeventlistener arrow keys 
Javascript :: stop interval js 
Javascript :: how to collect keys using lodash javascript 
Javascript :: question mark and colon in javascript 
Javascript :: vanilla javascript fade out 
Javascript :: json array 
Javascript :: found page without a React Component as default export in 
Javascript :: watch with multiple variables vuejs 
Javascript :: js get last element of array 
Javascript :: Sort objects of objects by nested property 
Javascript :: Sort big numbers from an array in javascript 
Javascript :: sweet alert in java Script 
Javascript :: split string based on length in javascript 
Javascript :: how to know if ajax is running 
Javascript :: jquery change page on click 
Javascript :: How to use body-parser package in using npm 
Javascript :: mv multiple directories 
Javascript :: js string slicing 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =