Skip to content

Instantly share code, notes, and snippets.

@frivolta
Last active September 4, 2020 07:46
Show Gist options
  • Save frivolta/9b162985396ab2b29e477287ab0092d7 to your computer and use it in GitHub Desktop.
Save frivolta/9b162985396ab2b29e477287ab0092d7 to your computer and use it in GitHub Desktop.
index.tsx - typing-react-context-v1
import * as React from "react";
import { render } from "react-dom";
import { SidebarProvider, useSidebarContext } from "./useSidebarContext";
import { ChildComponent } from "./childComponent";
export const App = () => {
const [isOpen] = useSidebarContext();
return (
<div>
<p>Main component context: {isOpen ? "Open" : "Closed"}</p>
<ChildComponent />
</div>
);
};
const rootElement = document.getElementById("root");
render(
<SidebarProvider>
<App />
</SidebarProvider>,
rootElement
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment