diff --git a/src/components/common/DomListener.tsx b/src/components/common/DomListener.tsx index 5e7a397..348d6d4 100644 --- a/src/components/common/DomListener.tsx +++ b/src/components/common/DomListener.tsx @@ -1,5 +1,4 @@ import React, { Component } from "react"; -import ReactDOM from "react-dom"; // no tests because js-dom doesn't support MutationObserver // https://github.com/jsdom/jsdom/issues/639 @@ -24,15 +23,16 @@ export class DomListener extends Component { public observer: MutationObserver; private readonly onResize: () => void; private readonly onDomChange: () => void; + private readonly rootRef: React.RefObject; constructor(props: DomListenerProps) { super(props); this.onResize = this.onUpdateHeight("resize").bind(this); this.onDomChange = this.onUpdateHeight("domChange").bind(this); this.observer = new MutationObserver(this.onDomChange); + this.rootRef = React.createRef(); } componentDidMount(): void { - // eslint-disable-next-line react/no-find-dom-node - const rootNode = ReactDOM.findDOMNode(this); + const rootNode = this.rootRef.current; if (rootNode) { this.observer.observe(rootNode, { attributes: true, childList: true, subtree: true, characterData: true }); // need an initial trigger, make it run on next tick :shrug: @@ -51,6 +51,6 @@ export class DomListener extends Component { } render(): React.ReactNode { - return
{this.props.children}
; + return
{this.props.children}
; } } diff --git a/src/types.ts b/src/types.ts index 5ab82fd..66508cc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,9 @@ import { ComponentType } from "react"; import { v2, WrappedDocument, OpenAttestationDocument, v3, SignedVerifiableCredential } from "@trustvc/trustvc"; +export type Document = SignedVerifiableCredential | OpenAttestationDocument; +export type { OpenAttestationDocument, SignedVerifiableCredential } from "@trustvc/trustvc"; + export type Attachment = v2.Attachment | v3.Attachment; export interface Renderer { attachment: Attachment; @@ -9,7 +12,7 @@ export interface Renderer { export interface TemplateProps { document: D; wrappedDocument?: WrappedDocument | SignedVerifiableCredential; - handleObfuscation: (field: string) => void; + handleObfuscation?: (field: string) => void; errorType?: string; }