Created
December 18, 2021 08:23
-
-
Save 0xLDev/fcee0d4804ad42d29aba4a8bf01aad59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useCallback } from "react"; | |
export const useToggle = (initialState = false) => { | |
const [state, setState] = useState(!!initialState); | |
const toggle = useCallback(() => setState((prev) => !prev), []); | |
return [state, toggle]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment