Skip to content

Instantly share code, notes, and snippets.

@frivolta
Created September 4, 2020 07:47
Show Gist options
  • Save frivolta/4851b9188a08f6484293d59b73515704 to your computer and use it in GitHub Desktop.
Save frivolta/4851b9188a08f6484293d59b73515704 to your computer and use it in GitHub Desktop.
useSidebar.tsx - typing-react-context-v1
import { useState, useEffect } from "react";
export type UseSidebar = [
boolean,
React.Dispatch<React.SetStateAction<boolean>>
];
export const useSidebar = (newOpenValue: boolean): UseSidebar => {
const [isOpen, setIsOpen] = useState(true);
useEffect(() => {
setIsOpen(newOpenValue);
}, [newOpenValue]);
return [isOpen, setIsOpen];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment