Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
renderDocument = doc => {
if (!doc) {
this.setState({ document: null })
return
}
this.setState({ loading: true })
try {
pdf(doc)
.toBlob()
.then(blob => {
const url = URL.createObjectURL(blob)
if (this.props.onUrlChange) {
this.props.onUrlChange(url)
}
this.setState({ document: url, loading: false })
})
} catch (error) {
this.props.onRenderError && this.props.onRenderError(error.message)
}
}