Skip to content

Commit feb8310

Browse files
authored
Merge pull request #17 from ishpaul777/feat/adds-onError-prop
adds onError prop
2 parents 90cd5e3 + d2df235 commit feb8310

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/PDFPreviewer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Props = {
2727
renderPasswordForm?: ({isPasswordInvalid, onSubmit, onPasswordChange}: Omit<PDFPasswordFormProps, 'onPasswordFieldFocus'>) => ReactNode | null;
2828
LoadingComponent?: ReactNode;
2929
ErrorComponent?: ReactNode;
30+
shouldShowErrorComponent?: boolean;
31+
onLoadError?: () => void;
3032
containerStyle?: CSSProperties;
3133
contentContainerStyle?: CSSProperties;
3234
};
@@ -43,6 +45,8 @@ const propTypes = {
4345
renderPasswordForm: PropTypes.func,
4446
LoadingComponent: PropTypes.node,
4547
ErrorComponent: PropTypes.node,
48+
shouldShowErrorComponent: PropTypes.bool,
49+
onLoadError: PropTypes.func,
4650
// eslint-disable-next-line react/forbid-prop-types
4751
containerStyle: PropTypes.object,
4852
// eslint-disable-next-line react/forbid-prop-types
@@ -56,8 +60,10 @@ const defaultProps = {
5660
renderPasswordForm: null,
5761
LoadingComponent: <p>Loading...</p>,
5862
ErrorComponent: <p>Failed to load the PDF file :(</p>,
63+
shouldShowErrorComponent: true,
5964
containerStyle: {},
6065
contentContainerStyle: {},
66+
onLoadError: () => {},
6167
};
6268

6369
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'}));
@@ -74,6 +80,8 @@ function PDFPreviewer({
7480
renderPasswordForm,
7581
containerStyle,
7682
contentContainerStyle,
83+
shouldShowErrorComponent,
84+
onLoadError,
7785
}: Props) {
7886
const [pageViewports, setPageViewports] = useState<PageViewport[]>([]);
7987
const [numPages, setNumPages] = useState(0);
@@ -237,7 +245,8 @@ function PDFPreviewer({
237245
file={file}
238246
options={DEFAULT_DOCUMENT_OPTIONS}
239247
externalLinkTarget={DEFAULT_EXTERNAL_LINK_TARGET}
240-
error={ErrorComponent}
248+
error={shouldShowErrorComponent ? ErrorComponent : null}
249+
onLoadError={onLoadError}
241250
loading={LoadingComponent}
242251
onLoadSuccess={onDocumentLoadSuccess}
243252
onPassword={initiatePasswordChallenge}

0 commit comments

Comments
 (0)