Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 37ddd04

Browse files
committed
Add forwardRef hoc
1 parent e4a414c commit 37ddd04

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

framework/react/components/HTMLPage.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
/// <reference lib="dom" />
22

3-
import React, { useEffect, useRef, RefObject, PropsWithRef, HTMLAttributes } from 'https://esm.sh/[email protected]'
3+
import React, { useEffect, useRef, PropsWithRef, HTMLAttributes } from 'https://esm.sh/[email protected]'
44
import { redirect } from '../../core/redirect.ts'
55

66
type HTMLPageProps = PropsWithRef<HTMLAttributes<{}> & {
7-
ref?: RefObject<HTMLDivElement>
87
html: string
98
}>
109

11-
export default function HTMLPage({
12-
ref: pRef,
13-
html,
14-
children,
15-
dangerouslySetInnerHTML,
16-
...rest
17-
}: HTMLPageProps) {
10+
const HTMLPage = React.forwardRef<HTMLDivElement, HTMLPageProps>((props, pRef) => {
11+
const {
12+
html,
13+
children,
14+
dangerouslySetInnerHTML,
15+
...rest
16+
} = props
1817
const ref = useRef<HTMLDivElement>(null)
1918

2019
useEffect(() => {
21-
const REF = pRef || ref
20+
const REF: any = pRef || ref
2221
const anchors: HTMLAnchorElement[] = []
2322
const onClick = (e: MouseEvent) => {
2423
e.preventDefault()
@@ -45,4 +44,6 @@ export default function HTMLPage({
4544
ref: pRef || ref,
4645
dangerouslySetInnerHTML: { __html: html }
4746
})
48-
}
47+
})
48+
49+
export default HTMLPage

0 commit comments

Comments
 (0)