Skip to content

Instantly share code, notes, and snippets.

@goldhand
Created June 27, 2017 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldhand/c5d174be3470d139a5ae68592d1f76e6 to your computer and use it in GitHub Desktop.
Save goldhand/c5d174be3470d139a5ae68592d1f76e6 to your computer and use it in GitHub Desktop.
Render upload method on react class
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