Last active
October 23, 2016 17:48
-
-
Save webpapaya/4d78987e91cc135eae633d97cf7f4379 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
const createActions = () => { | |
const signIn = () => new Promise((resolve) => { | |
setTimeout(resolve, 1000) | |
}); | |
return { signIn }; | |
}; | |
const Loading = () => { | |
return ( | |
<div>Loading...<div> | |
) | |
} | |
class SignInScreen extends React.Component { | |
state = { | |
isLoading: false | |
} | |
render() { | |
const onSignIn = () => Promise.resolve() | |
.then(() => this.setState({ isLoading: true })) | |
.then(() => this.props.onSignIn()) | |
.then(() => this.setState({ isLoading: false })) | |
.catch(() => this.setState({ isLoading: false })) | |
if (this.state.isLoading) { return <Loading />; } | |
return ( | |
<div> | |
<button onClick={ onSignIn }>SignIn</button> | |
</div> | |
); | |
} | |
} | |
const actions = createActions(); | |
ReactDOM.render( | |
<SignInScreen onSignIn={ actions.signIn } /> | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment