From ec0dd79dbe46a12410f4122fd56a17df359660e5 Mon Sep 17 00:00:00 2001 From: Arkadii Shvartcman Date: Sat, 18 May 2024 16:33:58 +0200 Subject: [PATCH 1/2] make ref unrequried for forward ref --- deno_dist/jsx/hooks/index.ts | 4 ++-- src/jsx/hooks/dom.test.tsx | 8 ++++++++ src/jsx/hooks/index.ts | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/deno_dist/jsx/hooks/index.ts b/deno_dist/jsx/hooks/index.ts index 93e63b22e..59df5e344 100644 --- a/deno_dist/jsx/hooks/index.ts +++ b/deno_dist/jsx/hooks/index.ts @@ -370,8 +370,8 @@ export const createRef = (): RefObject => { } export const forwardRef = ( - Component: (props: P, ref: RefObject) => JSX.Element -): ((props: P & { ref: RefObject }) => JSX.Element) => { + Component: (props: P, ref?: RefObject) => JSX.Element +): ((props: P & { ref?: RefObject }) => JSX.Element) => { return (props) => { const { ref, ...rest } = props return Component(rest as P, ref) diff --git a/src/jsx/hooks/dom.test.tsx b/src/jsx/hooks/dom.test.tsx index a824019a8..bbe84b9c4 100644 --- a/src/jsx/hooks/dom.test.tsx +++ b/src/jsx/hooks/dom.test.tsx @@ -497,6 +497,14 @@ describe('Hooks', () => { expect(root.innerHTML).toBe('
') expect(ref.current).toBeInstanceOf(HTMLElement) }) + + it('can run without ref', () => { + const App = forwardRef((props,) => { + return
+ }) + render(, root) + expect(root.innerHTML).toBe('
') + }) }) describe('useImperativeHandle()', () => { diff --git a/src/jsx/hooks/index.ts b/src/jsx/hooks/index.ts index d142d44af..ef51f2c65 100644 --- a/src/jsx/hooks/index.ts +++ b/src/jsx/hooks/index.ts @@ -370,8 +370,8 @@ export const createRef = (): RefObject => { } export const forwardRef = ( - Component: (props: P, ref: RefObject) => JSX.Element -): ((props: P & { ref: RefObject }) => JSX.Element) => { + Component: (props: P, ref?: RefObject) => JSX.Element +): ((props: P & { ref?: RefObject }) => JSX.Element) => { return (props) => { const { ref, ...rest } = props return Component(rest as P, ref) From a0fe342686915e434db43fe4f4ad6d83322ba724 Mon Sep 17 00:00:00 2001 From: Arkadii Shvartcman Date: Sat, 18 May 2024 16:38:10 +0200 Subject: [PATCH 2/2] make ref unrequried for forward ref --- src/jsx/hooks/dom.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jsx/hooks/dom.test.tsx b/src/jsx/hooks/dom.test.tsx index bbe84b9c4..7ed3a57c8 100644 --- a/src/jsx/hooks/dom.test.tsx +++ b/src/jsx/hooks/dom.test.tsx @@ -499,7 +499,7 @@ describe('Hooks', () => { }) it('can run without ref', () => { - const App = forwardRef((props,) => { + const App = forwardRef((props) => { return
}) render(, root)