Skip to content

Instantly share code, notes, and snippets.

@izszzz
Last active July 16, 2021 19:56
Show Gist options
  • Save izszzz/d9e7a0946e1bbb9ce05d96866549d4fc to your computer and use it in GitHub Desktop.
Save izszzz/d9e7a0946e1bbb9ce05d96866549d4fc to your computer and use it in GitHub Desktop.
React useOpen.ts

useOpen

Example

const [open, handleOpen, handleClose] = useOpen()
import { useState } from "react";
const useOpen = (): [boolean, () => void, () => void] => {
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return [open, handleOpen, handleClose];
};
export default useOpen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment