Skip to content

Commit

Permalink
feat: onHTMLLoaded prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent 6c07b8d commit 981b49b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/render-html/src/LoadHTML.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function loadHTMLResource(uri: string): Promise<LoaderInternalState> {
}

function useLoader(props: HTMLLoaderProps) {
const { uri, html } = props;
const { uri, html, onHTMLLoaded } = props;
const [loadState, setState] = useState<LoaderInternalState>({
error: false,
loading: false,
Expand All @@ -55,6 +55,9 @@ function useLoader(props: HTMLLoaderProps) {
cancelled = true;
};
}, [error, uri]);
useEffect(() => {
loadState.resolvedHTML && onHTMLLoaded?.call(null, loadState.resolvedHTML);
}, [loadState.resolvedHTML, onHTMLLoaded]);
return loadState;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/render-html/src/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ export interface RenderHTMLProps<P = any>
* Triggered when the transient render tree changes. Useful for debugging.
*/
onTTreeChange?: (ttree: TNode) => void;
/**
* Triggered when HTML is available to the RenderHTML component.
*/
onHTMLLoaded?: (html: string) => void;
/**
* A list of fonts available in the current platform. These fonts will used
* to select the first match in CSS `fontFamily` property, which supports a
Expand Down

0 comments on commit 981b49b

Please sign in to comment.