Skip to content

Instantly share code, notes, and snippets.

@pllearns
Created January 14, 2017 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pllearns/488fce70c5a33b526b67f38591d975ab to your computer and use it in GitHub Desktop.
Save pllearns/488fce70c5a33b526b67f38591d975ab to your computer and use it in GitHub Desktop.
React Router - Rethinking what can be passed through.
import ReactDom from 'react-dom'
import {Component} from 'react'
import React from 'react'
import { Router, Route, browserHistory } from 'react-router'
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
import LandingPage from './LandingPage'
import ScheduleSession from './ScheduleSession'
import ActivateCoach from './ActivateCoach'
import CoachLanding from './CoachLanding'
import fetchMethod from './fetchMethod'
export default class ReactRouter extends Component {
constructor(props) {
super(props)
this.state = {
coach: null
}
}
fetchCoach() {
const path = 'api/v1/coaches/findCoach'
const callback = coach => {
this.setState({
coach: coach
})
}
return fetchMethod('GET', path, null).then(callback)
}
updateCoach(coachFields) {
this.setState({coach: Object.assign({}, this.state.coach, coachFields)})
}
componentDidMount() {
this.fetchCoach()
}
render() {
return <MuiThemeProvider>
<Router history={browserHistory}>
<Route path="/" component={(props, state, params) => <LandingPage coach={this.state.coach}/>}/>
<Route path="/schedule_session"
component={(props, state, params) =>
<ScheduleSession coach={this.state.coach} />}/>
<Route path="/coach_landing"
component={(props, state, params) =>
<CoachLanding coach={this.state.coach}
updateCoachCallback={this.updateCoach.bind(this)} />}/>
</Router>
</MuiThemeProvider>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment