Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Created October 21, 2016 14:39
Show Gist options
  • Save bnhansn/008917480fcc03e31f4b093b7189ede4 to your computer and use it in GitHub Desktop.
Save bnhansn/008917480fcc03e31f4b093b7189ede4 to your computer and use it in GitHub Desktop.
// @flow
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { logout } from '../../actions/session';
import Navbar from '../../components/Navbar';
type Props = {
logout: () => void,
currentUser: Object,
isAuthenticated: boolean,
}
class Home extends Component {
static contextTypes = {
router: PropTypes.object,
}
props: Props
handleLogout = () => this.props.logout(this.context.router);
render() {
const { currentUser, isAuthenticated } = this.props;
return (
<div style={{ flex: '1' }}>
<Navbar />
<ul>
<li><Link to="/login">Login</Link></li>
<li><Link to="/signup">Signup</Link></li>
</ul>
{isAuthenticated &&
<div>
<span>{currentUser.username}</span>
<button type="button" onClick={this.handleLogout}>Logout</button>
</div>
}
</div>
);
}
}
export default connect(
state => ({
isAuthenticated: state.session.isAuthenticated,
currentUser: state.session.currentUser,
}),
{ logout }
)(Home);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment