toggle in react js usestate code example
Example: 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>
)
}