Skip to content

Instantly share code, notes, and snippets.

@webpapaya
Last active October 23, 2016 20:24
Show Gist options
  • Save webpapaya/269a5eb969c4fcf896f206a938d55527 to your computer and use it in GitHub Desktop.
Save webpapaya/269a5eb969c4fcf896f206a938d55527 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import { waitAtLeast } from 'promise-frites';
//...
class SignInScreen extends React.Component {
state = {
isLoading: false
}
render() {
const waitAtLeast1Second = waitAtLeast(1);
const onSignIn = () => Promise.resolve()
.then(() => this.setState({ isLoading: true }))
.then(waitAtLeast1Second(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>
);
}
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment