Skip to content

Instantly share code, notes, and snippets.

@dev-cyprium
Created February 22, 2021 20:18
Show Gist options
  • Select an option

  • Save dev-cyprium/95fab3a0f3ee9ae63b29c6f25d2b7347 to your computer and use it in GitHub Desktop.

Select an option

Save dev-cyprium/95fab3a0f3ee9ae63b29c6f25d2b7347 to your computer and use it in GitHub Desktop.
Recap
import { createContext, useContext, useState, useEffect } from "react";
const RouterContext = createContext(/* Context */);
const Home = () => {
/* The route view */
}
const Page = () => {
/* The page view */
}
const AppRouter = ({ children }) => {
/* Storing the state and providing it to the rest of the application */
};
const RouterView = ({ config }) => {
/* Dynamically rendering the component that's 'selected' */
};
export default function App() {
return (
<AppRouter>
{/* ... rest of the markup */}
<main className="flex-1 px-4 py-2">
<RouterView config={{ "/": Home, "/page": Page }} />
</main>
</AppRouter>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment