usestate hook for checkbox check and uncheck

Solutions on MaxInterview for usestate hook for checkbox check and uncheck by the best coders in the world

showing results for - "usestate hook for checkbox check and uncheck"
Beatrice
26 Aug 2017
1const { useState } = React; // --> for inline use
2// import React, { useState } from 'react';  // --> for real project
3
4
5const App = () => {
6  const [checked, setChecked] = useState(false)
7  const handleClick = () => setChecked(!checked)
8  
9  return <input onClick={handleClick} checked={checked} type="checkbox" />
10};
11
12
13ReactDOM.render(<App />, document.getElementById('root'))