Skip to content

Instantly share code, notes, and snippets.

@EduVencovsky
Created September 25, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduVencovsky/61ff7bd6293f416d5b9c7f489d0f951b to your computer and use it in GitHub Desktop.
Save EduVencovsky/61ff7bd6293f416d5b9c7f489d0f951b to your computer and use it in GitHub Desktop.
import { useState } from 'react'
export default function useToggle(defaultValue){
const [state, setState] = useState(defaultValue)
const toggle = (value = null) => {
if(value == null)
setState(!state)
else
setState(!!value)
}
return [state, toggle]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment