Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
useSidebarContext.tsx - typing-react-context-v2
import * as React from "react";
import { useSidebar, UseSidebar } from "./useSidebar";
import { createGenericContext } from "./createGenericContext";
interface Props {
children: React.ReactNode;
}
// Generate context
const [useSidebarContext, SidebarContextProvider] = createGenericContext<
UseSidebar
>();
// Generate provider
const SidebarProvider = ({ children }: Props) => {
const [isOpen, setIsOpen] = useSidebar(true);
return (
<SidebarContextProvider value={[isOpen, setIsOpen]}>
{children}
</SidebarContextProvider>
);
};
export { useSidebarContext, SidebarProvider };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment