Advertisement
Guest User

Untitled

a guest
Feb 9th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Router, Route, browserHistory } from 'react-router';
  3. import Login from './Login';
  4. import Courses from './Courses';
  5.  
  6. class App extends Component {
  7. constructor() {
  8. super();
  9.  
  10. this.state = {
  11. username: '',
  12. password: ''
  13. };
  14. }
  15.  
  16. setCredentials = ({ username, password }) => {
  17. this.setState({
  18. username,
  19. password
  20. });
  21. }
  22.  
  23. render() {
  24. return (
  25. <Router history={browserHistory}>
  26. <Route
  27. path='/'
  28. component={Login}
  29. setCredentials={this.setCredentials}
  30. />
  31. <Route
  32. path='/courses'
  33. component={Courses}
  34. credentials={this.state}
  35. />
  36. </Router>
  37. );
  38. }
  39. }
  40.  
  41. componentWillReceiveProps(nextProps) {
  42. if(nextProps.isAuthenticated && this.props.credentials !== nextProps.credentials) {
  43. // perform fetch for courses here
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement