Skip to content

Instantly share code, notes, and snippets.

@frivolta
Created September 4, 2020 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frivolta/9e8c5f35df9c63e353eed60a364379f9 to your computer and use it in GitHub Desktop.
Save frivolta/9e8c5f35df9c63e353eed60a364379f9 to your computer and use it in GitHub Desktop.
useSidebarContext.tsx - typing-react-context-v1-v2
import React from "react";
import { useSidebarContext } from "./useSidebarContext";
export const ChildComponent: React.FC = () => {
const [isOpen, setIsOpen] = useSidebarContext();
return (
<>
<p>Sidebar is: {isOpen ? "Open" : "Closed"}</p>
<button onClick={() => setIsOpen(!isOpen)}>Toggle sidebar</button>
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment