Created
November 11, 2016 17:20
-
-
Save mauricedb/491c33efd678a80628464a7162cab7d7 to your computer and use it in GitHub Desktop.
Remember me
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 AppPresentation from './app-presentation'; | |
class AppContainer extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { user: null }; | |
this.loginAsUser = this.loginAsUser.bind(this); | |
} | |
componentWillMount() { | |
if (localStorage.user) { | |
try { | |
const user = JSON.parse(localStorage.user); | |
this.setState({ user }); | |
} catch (e) { | |
// eslint-disable-next-line no-console | |
console.error(e); | |
} | |
} | |
} | |
loginAsUser(user) { | |
if (user.rememberMe) { | |
localStorage.user = JSON.stringify(user); | |
} | |
this.setState({ user }); | |
} | |
render() { | |
const { user } = this.state; | |
return ( | |
<AppPresentation | |
user={user} | |
loginAsUser={this.loginAsUser} | |
/> | |
); | |
} | |
} | |
export default AppContainer; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment