Skip to content

Instantly share code, notes, and snippets.

@ponyjackal
Created September 17, 2020 23:45
Show Gist options
  • Save ponyjackal/e2fb2cf88a9234a4c0191fbb44bd5409 to your computer and use it in GitHub Desktop.
Save ponyjackal/e2fb2cf88a9234a4c0191fbb44bd5409 to your computer and use it in GitHub Desktop.
useToggle
import React, { useState, useEffect, useCallback } from "react";
const useToggle = (initState = false) => {
const [status, setStatus] = useState(initState);
const toggle = useCallback(() => {
setStatus((status) => {
return !status;
});
}, []);
return [status, toggle];
};
export default useToggle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment