Skip to content

Instantly share code, notes, and snippets.

@flintinatux
Created May 31, 2018 14:13
Show Gist options
  • Save flintinatux/809d0e1410106e6c64270fdd423a1d9a to your computer and use it in GitHub Desktop.
Save flintinatux/809d0e1410106e6c64270fdd423a1d9a to your computer and use it in GitHub Desktop.
One way to simplify routing in React
const Layout = Child => props =>
<div>
<header></header>
<main>
<Child />
</main>
</div>
export default Layout
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>
)
import Layout from './Layout'
const Profile = props =>
<div class="profile"></div>
export default Layout(Profile)
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