Skip to content

Instantly share code, notes, and snippets.

@zxqx
Last active March 12, 2016 06:42
Show Gist options
  • Save zxqx/de92a703b8a5dcf16fe6 to your computer and use it in GitHub Desktop.
Save zxqx/de92a703b8a5dcf16fe6 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { connect } from 'react-redux';
import Header from '../../components/header';
import { attemptUserAuthentication, logoutAndRedirect } from '../../actions/auth';
import { getUserInfo, sendConfirmationEmail } from '../../actions/users';
@connect(state => ({
auth: state.auth,
users: state.users
}))
export default class App extends Component {
componentWillMount() {
this.props.dispatch(attemptUserAuthentication());
}
componentWillReceiveProps() {
const { dispatch, auth, users } = this.props;
if (auth.isAuthenticated && !users) {
dispatch(getUserInfo());
}
}
render() {
const { dispatch, users, children } = this.props;
return (
<div className="app">
<Header
user={users}
onLogout={() => dispatch(logoutAndRedirect())}
onResendEmail={() => dispatch(sendConfirmationEmail())} />
{children}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment