Created
June 27, 2017 15:47
-
-
Save goldhand/c5d174be3470d139a5ae68592d1f76e6 to your computer and use it in GitHub Desktop.
Render upload method on react class
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
class Upload extends Component { | |
/** | |
* Renders one of [renderProgress, renderEnd, renderUnknown] depending on | |
* the XMLHttpRequest.status | |
* @returns {Object} Video placeholder with progress bar | |
*/ | |
get renderUpload(): React$Element<*> { | |
const {getUpload} = this.props; | |
const { | |
status, | |
} = getUpload(); | |
switch (status) { | |
case XMLHttpRequest.LOADING: | |
// in a loading state | |
return this.renderProgress; | |
case XMLHttpRequest.DONE: | |
// upload is complete | |
return this.renderEnd; | |
case XMLHttpRequest.UNSENT: | |
case XMLHttpRequest.OPENED: | |
case XMLHttpRequest.HEADERS_RECEIVED: | |
default: | |
// upload has not started or status is unknown | |
return this.renderUnknown; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment