Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: xhr request 
Javascript :: javascript get random items from array 
Javascript :: tab active check 
Javascript :: how get checkbox if checked in jquery 
Javascript :: how to run angular application in visual studio code 
Javascript :: express body-parser is depreciated 
Javascript :: base64 to png nodejs 
Javascript :: what is the use of angularjs 
Javascript :: swapping elements in an array 
Javascript :: swiftyjson 
Javascript :: use import in node 
Javascript :: livewire upload file progress indicator 
Javascript :: regex any char except 
Javascript :: materialize for react 
Javascript :: how to check which key is pressed in jquery 
Javascript :: push items to associative array jquery 
Javascript :: onclick open link js 
Javascript :: vertical align text canvas 
Javascript :: ngchange angular 8 
Javascript :: json parse string 
Javascript :: js generate random number 
Javascript :: js array copy not reference 
Javascript :: settimeout inside loop 
Javascript :: random int javascript 
Javascript :: javascript get dictionary values 
Javascript :: queryselector data attribute 
Javascript :: click outside javascript 
Javascript :: how to check consecutive characters in javascript 
Javascript :: how to sort an array of objects by a property value in javascript 
Javascript :: on hover add class on children jquery 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =