Last active
December 15, 2020 22:09
-
-
Save JonahTurnquist/014bff3d5fef89c272aa1711cc10c057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; | |
// Layout | |
const Layout = ({ children }) => ( | |
<div> | |
<header>My header</header> | |
{children} | |
<header>My footer</header> | |
</div> | |
); | |
// HOC | |
const withLayout = (Component) => (props) => ( | |
<Layout> | |
{/* All props are passed through to the Component being wrapped */} | |
<Component {...props} /> / | |
</Layout> | |
); | |
// Pages | |
const PageA = withLayout(() => <p>This is Page A</p>); | |
const PageB = withLayout(() => <p>This is Page B</p>); | |
// Routes | |
export default function App() { | |
return ( | |
<Router> | |
<Switch> | |
<Route path="/pageA" component={PageA} /> | |
<Route path="/pageB" component={PageB} /> | |
</Switch> | |
</Router> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!