@@ -27,6 +27,8 @@ type Props = {
27
27
renderPasswordForm ?: ( { isPasswordInvalid, onSubmit, onPasswordChange} : Omit < PDFPasswordFormProps , 'onPasswordFieldFocus' > ) => ReactNode | null ;
28
28
LoadingComponent ?: ReactNode ;
29
29
ErrorComponent ?: ReactNode ;
30
+ shouldShowErrorComponent ?: boolean ;
31
+ onLoadError ?: ( ) => void ;
30
32
containerStyle ?: CSSProperties ;
31
33
contentContainerStyle ?: CSSProperties ;
32
34
} ;
@@ -43,6 +45,8 @@ const propTypes = {
43
45
renderPasswordForm : PropTypes . func ,
44
46
LoadingComponent : PropTypes . node ,
45
47
ErrorComponent : PropTypes . node ,
48
+ shouldShowErrorComponent : PropTypes . bool ,
49
+ onLoadError : PropTypes . func ,
46
50
// eslint-disable-next-line react/forbid-prop-types
47
51
containerStyle : PropTypes . object ,
48
52
// eslint-disable-next-line react/forbid-prop-types
@@ -56,8 +60,10 @@ const defaultProps = {
56
60
renderPasswordForm : null ,
57
61
LoadingComponent : < p > Loading...</ p > ,
58
62
ErrorComponent : < p > Failed to load the PDF file :(</ p > ,
63
+ shouldShowErrorComponent : true ,
59
64
containerStyle : { } ,
60
65
contentContainerStyle : { } ,
66
+ onLoadError : ( ) => { } ,
61
67
} ;
62
68
63
69
pdfjs . GlobalWorkerOptions . workerSrc = URL . createObjectURL ( new Blob ( [ pdfWorkerSource ] , { type : 'text/javascript' } ) ) ;
@@ -74,6 +80,8 @@ function PDFPreviewer({
74
80
renderPasswordForm,
75
81
containerStyle,
76
82
contentContainerStyle,
83
+ shouldShowErrorComponent,
84
+ onLoadError,
77
85
} : Props ) {
78
86
const [ pageViewports , setPageViewports ] = useState < PageViewport [ ] > ( [ ] ) ;
79
87
const [ numPages , setNumPages ] = useState ( 0 ) ;
@@ -237,7 +245,8 @@ function PDFPreviewer({
237
245
file = { file }
238
246
options = { DEFAULT_DOCUMENT_OPTIONS }
239
247
externalLinkTarget = { DEFAULT_EXTERNAL_LINK_TARGET }
240
- error = { ErrorComponent }
248
+ error = { shouldShowErrorComponent ? ErrorComponent : null }
249
+ onLoadError = { onLoadError }
241
250
loading = { LoadingComponent }
242
251
onLoadSuccess = { onDocumentLoadSuccess }
243
252
onPassword = { initiatePasswordChallenge }
0 commit comments