Answers for "toggle switch using useState"

0

toggle switch using useState

import React, { useState } from 'react';

function ToggleSwitch() {
  const [value, setValue] = useState(false);
  
  function toggleHandler {
    setValue(value => !value);
    console.log(value);
  }
  
  return (
  	<button onClick={toggleHandler} > Click Me </button>
  	)
}
Posted by: Guest on July-21-2021

Code answers related to "toggle switch using useState"

Code answers related to "Javascript"

Browse Popular Code Answers by Language