Last active
June 3, 2018 11:18
-
-
Save juanmaguitar/134f5d188d5aa4e722bdb1cd8332a781 to your computer and use it in GitHub Desktop.
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 { 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