Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

usestate hook for checkbox check and uncheck

const { useState } = React; // --> for inline use
// import React, { useState } from 'react';  // --> for real project


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


ReactDOM.render(<App />, document.getElementById('root'))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #usestate #hook #checkbox #check #uncheck
ADD COMMENT
Topic
Name
1+2 =