Skip to content

Instantly share code, notes, and snippets.

@0xLDev
Created December 18, 2021 08:23
Show Gist options
  • Save 0xLDev/fcee0d4804ad42d29aba4a8bf01aad59 to your computer and use it in GitHub Desktop.
Save 0xLDev/fcee0d4804ad42d29aba4a8bf01aad59 to your computer and use it in GitHub Desktop.
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