@@ -35,6 +35,7 @@ export interface InputProps {
3535}
3636
3737export interface ViewerState {
38+ wvInstance ?: WebViewerInstance ;
3839 isDocumentLoaded : boolean ;
3940 currentFileId ?: number ;
4041}
@@ -43,12 +44,11 @@ const hasAttribute = (attribute: any): boolean => attribute && attribute.status
4344
4445class PDFViewer extends React . Component < InputProps , ViewerState > {
4546 viewerRef : React . RefObject < HTMLDivElement > ;
46- wvInstance ?: WebViewerInstance ;
4747 constructor ( props : InputProps ) {
4848 super ( props ) ;
4949 this . viewerRef = React . createRef ( ) ;
50- this . wvInstance = undefined ;
5150 this . state = {
51+ wvInstance : undefined ,
5252 isDocumentLoaded : false ,
5353 currentFileId : undefined
5454 } ;
@@ -76,7 +76,7 @@ class PDFViewer extends React.Component<InputProps, ViewerState> {
7676 ) . then ( ( instance : WebViewerInstance ) => {
7777 const { Core, UI } = instance ;
7878
79- this . wvInstance = instance ;
79+ this . setState ( { wvInstance : instance } ) ;
8080
8181 UI . setLanguage ( this . props . defaultLanguage ) ;
8282
@@ -261,9 +261,9 @@ class PDFViewer extends React.Component<InputProps, ViewerState> {
261261 }
262262 componentWillUnmount ( ) : void {
263263 // Perform clean-up of WV when unmounted
264- if ( this . wvInstance ) {
264+ if ( this . state . wvInstance ) {
265265 // Disposing WV events
266- this . wvInstance . UI . dispose ( ) ;
266+ this . state . wvInstance . UI . dispose ( ) ;
267267 }
268268 }
269269 render ( ) : ReactNode {
0 commit comments