Skip to content

Instantly share code, notes, and snippets.

@juanmaguitar
Last active June 3, 2018 11:18
Show Gist options
  • Save juanmaguitar/134f5d188d5aa4e722bdb1cd8332a781 to your computer and use it in GitHub Desktop.
Save juanmaguitar/134f5d188d5aa4e722bdb1cd8332a781 to your computer and use it in GitHub Desktop.
import { lifecycle } from "recompose";
const getPendingMessages = () => {
const randomNumber = Math.ceil(Math.random() * 10);
return new Promise(resolve => {
setTimeout(() => resolve(randomNumber), randomNumber * 1000);
});
};
const withDidMountStateMessages = lifecycle({
componentDidMount() {
this.setState({ loading: true });
getPendingMessages().then(messages => {
this.setState({ loading: false, messages });
});
}
});
export default withDidMountStateMessages;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment