Created
January 14, 2017 05:30
-
-
Save pllearns/488fce70c5a33b526b67f38591d975ab to your computer and use it in GitHub Desktop.
React Router - Rethinking what can be passed through.
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 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