Created
October 28, 2017 13:27
-
-
Save Aperyon/31b88ee2296d0756b9bdcd5fd82f4709 to your computer and use it in GitHub Desktop.
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
export const CHANGE_LOGGED_IN = 'CHANGE_LOGGED_IN'; | |
export const changeLoggedIn = (newValue) => ({ | |
type: CHANGE_LOGGED_IN, | |
newValue: newValue, | |
}); |
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 React, { Component } from 'react'; | |
import { Route, Switch } from 'react-router-dom'; | |
import { connect } from 'react-redux'; | |
import Loading from './Loading'; | |
import Login from './Login'; | |
import App from './App'; | |
import { changeLoggedIn } from './actions'; | |
class ActuallyMainApp extends Component { | |
componentDidMount() { | |
const that = this; | |
setTimeout(() => { that.props.changeLoggedIn(true) }, 300); | |
} | |
render() { | |
if (this.props.loggedIn === null) { | |
return <Loading /> | |
} | |
return ( | |
<Switch> | |
<Route path="/login/" component={Login} /> | |
<Route component={App} /> | |
</Switch> | |
) | |
} | |
} | |
export default connect( | |
state => ({ | |
loggedIn: state.loggedIn, | |
}), { | |
changeLoggedIn, | |
} | |
)(ActuallyMainApp) |
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 React from 'react'; | |
import { connect } from 'react-redux'; | |
import { Link, Redirect, Route, Switch } from 'react-router-dom'; | |
const Nav = () => ( | |
<ul> | |
<Link to="/friends/"><li>Friends</li></Link> | |
<Link to="/books/"><li>Books</li></Link> | |
</ul> | |
) | |
const Friends = () => <h1>Friends</h1> | |
const Books = () => <h1>Books</h1> | |
const App = () => ( | |
<div> | |
<Nav /> | |
<Switch> | |
<Route exact path="/friends/" component={Friends} /> | |
<Route exact path="/books/" component={Books} /> | |
<Redirect exact from="/" to="/friends/" /> | |
</Switch> | |
</div> | |
) | |
export default connect( | |
state => ({ | |
loggedIn: state.loggedIn, | |
}) | |
)(App); |
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 React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { BrowserRouter } from 'react-router-dom'; | |
import { Provider } from 'react-redux'; | |
import { createStore } from 'redux' | |
import ActuallyMainApp from './ActuallyMainApp'; | |
import reducers from './reducers'; | |
ReactDOM.render( | |
<Provider store={createStore(reducers)}> | |
<BrowserRouter> | |
<ActuallyMainApp /> | |
</BrowserRouter> | |
</Provider>, | |
document.getElementById('root') | |
); |
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 React from 'react'; | |
const Loading = () => <h1>Loading</h1> | |
export default Loading |
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 React from 'react' | |
const Login = () => <h1>Login</h1> | |
export default Login; |
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 { combineReducers } from 'redux'; | |
import { CHANGE_LOGGED_IN } from './actions'; | |
const loggedInReducer = ( state = null, action) => { | |
switch (action.type) { | |
case CHANGE_LOGGED_IN: return action.newValue; | |
default: return state; | |
}; | |
}; | |
const reducers = combineReducers({ | |
loggedIn: loggedInReducer, | |
}); | |
export default reducers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment