|
|
@@ -1,5 +1,5 @@
|
|
|
import React, {
|
|
|
- useCallback, useEffect, useMemo, useState, SyntheticEvent,
|
|
|
+ useCallback, useEffect, useMemo, useState, SyntheticEvent, RefObject,
|
|
|
} from 'react';
|
|
|
|
|
|
|
|
|
@@ -15,23 +15,20 @@ declare const interceptorManager: InterceptorManager;
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
- appContainer: AppContainer,
|
|
|
-
|
|
|
markdown?: string,
|
|
|
pagePath?: string,
|
|
|
- inputRef?: React.RefObject<HTMLDivElement>,
|
|
|
isMathJaxEnabled?: boolean,
|
|
|
renderMathJaxOnInit?: boolean,
|
|
|
onScroll?: (scrollTop: number) => void,
|
|
|
}
|
|
|
|
|
|
+type UnstatedProps = Props & { appContainer: AppContainer };
|
|
|
|
|
|
-const Preview = (props: Props): JSX.Element => {
|
|
|
+const Preview = React.forwardRef((props: UnstatedProps, ref: RefObject<HTMLDivElement>): JSX.Element => {
|
|
|
|
|
|
const {
|
|
|
appContainer,
|
|
|
markdown, pagePath,
|
|
|
- inputRef,
|
|
|
} = props;
|
|
|
|
|
|
const [html, setHtml] = useState('');
|
|
|
@@ -90,7 +87,7 @@ const Preview = (props: Props): JSX.Element => {
|
|
|
return (
|
|
|
<div
|
|
|
className="page-editor-preview-body"
|
|
|
- ref={inputRef}
|
|
|
+ ref={ref}
|
|
|
onScroll={(event: SyntheticEvent<HTMLDivElement>) => {
|
|
|
if (props.onScroll != null) {
|
|
|
props.onScroll(event.currentTarget.scrollTop);
|
|
|
@@ -105,7 +102,7 @@ const Preview = (props: Props): JSX.Element => {
|
|
|
</div>
|
|
|
);
|
|
|
|
|
|
-};
|
|
|
+});
|
|
|
|
|
|
/**
|
|
|
* Wrapper component for using unstated
|
|
|
@@ -113,8 +110,8 @@ const Preview = (props: Props): JSX.Element => {
|
|
|
const PreviewWrapper = withUnstatedContainers(Preview, [AppContainer]);
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
-const PreviewWrapper2 = (props): JSX.Element => {
|
|
|
- return <PreviewWrapper {...props} />;
|
|
|
-};
|
|
|
+const PreviewWrapper2 = React.forwardRef((props: Props, ref: RefObject<HTMLDivElement>): JSX.Element => {
|
|
|
+ return <PreviewWrapper ref={ref} {...props} />;
|
|
|
+});
|
|
|
|
|
|
export default PreviewWrapper2;
|