Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useState settoggle


Pierre Ortega
@4ever
1:46am
const Toggle = () => {
  const [isToggledOn, setToggle] = useState(false)
  const toggle = () => setToggle(!isToggledOn)
  return (
     <button onClick={toggle}>
        {isToggleOn ? 'ON' : 'OFF'}
      </button>
  )
}
Comment

react hook toggle state

// import React, { useState } from 'react';
const { useState } = React;

function App() {
  const [checked, setChecked] = useState(false);
  const toggleChecked = () => setChecked(value => !value);
  return (
    <input
      type="checkbox"
      checked={checked}
      onChange={toggleChecked}
    />
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Comment

PREVIOUS NEXT
Code Example
Javascript :: copy localstorage javascript 
Javascript :: FileReader get filename 
Javascript :: js every x seconds 
Javascript :: javascript clone array of object 
Javascript :: inline style in nextjs 
Javascript :: copy to clipboard react native 
Javascript :: math.rount 
Javascript :: js enter key event listener 
Javascript :: router.query is undefined in first render 
Javascript :: angular maxlength directive input type number 
Javascript :: generate random string javascript 
Javascript :: how to redirect to another page in javascript on submit type 
Javascript :: array left rotation javascript 
Javascript :: vite install in vue 
Javascript :: eof while parsing 
Javascript :: Javascript convert html entity to string 
Javascript :: import { Application } from "express" 
Javascript :: js toggle boolean 
Javascript :: convert a string to an integer in javascript 
Javascript :: javascript for loop infinite 
Javascript :: how to see chrome sync storage and local storage 
Javascript :: xml http request 
Javascript :: react native linking email 
Javascript :: set css variable from javascript 
Javascript :: how to add checkbox in alert box in javascript 
Javascript :: how to get value from input field in javascript 
Javascript :: get all from dir node 
Javascript :: iconify/react - npm 
Javascript :: jest expect error to be thrown 
Javascript :: compare and filter two array of object 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =