Skip to content

Commit 892c7e3

Browse files
committed
forwardRef agnostic
1 parent f6f50f3 commit 892c7e3

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/preact.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
import { createElement } from "preact";
1+
import { createElement, options } from "preact";
22
import { useLayoutEffect, useRef } from "preact/hooks";
33
import { createAuto } from "./core/create-auto";
44
import { createWrapper } from "./core/create-wrapper";
55

6+
const { vnode } = options;
7+
8+
options.vnode = (node) => {
9+
if (typeof node.type === "function") {
10+
//@ts-ignore
11+
node.props.ref = node.ref;
12+
node.ref = null;
13+
}
14+
if (vnode) vnode(node);
15+
};
16+
617
const forwardRef =
7-
(component: (props: any, ref: any) => any) =>
18+
(callback: (...args: any[]) => any) =>
819
({ ref, ...props }: any) =>
9-
component(props, ref);
20+
callback(props, ref);
1021

1122
export const wrapper = createWrapper({
1223
createElement,

0 commit comments

Comments
 (0)