Last active
July 4, 2019 01:04
-
-
Save YKalashnikov/197380747ba87b112407607548571633 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
import React, { Component } from 'react'; | |
import { Switch, Route } from 'react-router-dom'; | |
import {connect} from 'react-redux'; | |
import {getProfileFetch, logoutUser} from './redux/actions'; | |
import Signup from './components/Signup'; | |
import Login from './components/Login'; | |
class App extends Component { | |
componentDidMount = () => { | |
this.props.getProfileFetch() | |
} | |
handleClick = event => { | |
event.preventDefault() | |
// Удаление token из localStorage | |
localStorage.removeItem("token") | |
// удаление из Redux хранилица | |
this.props.logoutUser() | |
} | |
render() { | |
return ( | |
<div> | |
<Switch> | |
<Route path="/signup" component={Signup}/> | |
<Route path="/login" component={Login}/> | |
</Switch> | |
{this.props.currentUser.username | |
? <button onClick={this.handleClick}>Log Out</button> | |
: null | |
} | |
</div> | |
); | |
} | |
} | |
const mapStateToProps = state => ({ | |
currentUser: state.reducer.currentUser | |
}) | |
const mapDispatchToProps = dispatch => ({ | |
getProfileFetch: () => dispatch(getProfileFetch()), | |
logoutUser: () => dispatch(logoutUser()) | |
}) | |
export default connect(mapStateToProps, mapDispatchToProps)(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment