Created
May 31, 2018 14:13
-
-
Save flintinatux/809d0e1410106e6c64270fdd423a1d9a to your computer and use it in GitHub Desktop.
One way to simplify routing in React
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
const Layout = Child => props => | |
<div> | |
<header></header> | |
<main> | |
<Child /> | |
</main> | |
</div> | |
export default Layout |
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 { render } from 'react-dom' | |
import { Route, Router } from 'react-router' | |
import Home from './Home' | |
import Profile from './Profile' | |
import Profiles from './Profiles' | |
render( | |
<Router> | |
<Route path='/' component={Home} /> | |
<Route path='/profiles' component={Profiles} /> | |
<Route path='/profiles/:id' component={Profile} /> | |
</Router> | |
) |
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 Layout from './Layout' | |
const Profile = props => | |
<div class="profile"></div> | |
export default Layout(Profile) |
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 Card from './Card' | |
import Layout from './Layout' | |
const Profiles = props => | |
<div class="profiles"> | |
{ props.profiles.map(Card) } | |
</div> | |
export default Layout(Profiles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment