Skip to content
Myr

fix(hono-jsx): make ref unrequried for forward ref (#2715)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* make ref unrequried for forward ref * make ref unrequried for forward ref

authored by Arkadii Shvartsman · committed by GitHub · parent ee9ccf8 · Browse files · 3 files+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+12 added−4 removed

  • tests:+8 added−0 removed
  • other:+4 added−4 removed

3 files+12 added−4 removed

modified:deno_dist/jsx/hooks/index.ts+2 added-2 removed
368 unmodified lines
369 return { current: null }370}371372export const forwardRef = <T, P = {}>(373 Component: (props: P, ref: RefObject<T>) => JSX.Element374): ((props: P & { ref: RefObject<T> }) => JSX.Element) => {373 Component: (props: P, ref?: RefObject<T>) => JSX.Element374): ((props: P & { ref?: RefObject<T> }) => JSX.Element) => {375 return (props) => {376 const { ref, ...rest } = props377 return Component(rest as P, ref)378 }
44 unmodified lines
modified:src/jsx/hooks/dom.test.tsx+8 added
495 unmodified lines
496 render(<App ref={ref} />, root)497 expect(root.innerHTML).toBe('<div></div>')498 expect(ref.current).toBeInstanceOf(HTMLElement)499 })500501 it('can run without ref', () => {502 const App = forwardRef((props) => {503 return <div {...props} />504 })505 render(<App />, root)506 expect(root.innerHTML).toBe('<div></div>')507 })508 })509510 describe('useImperativeHandle()', () => {511 it('simple', async () => {
96 unmodified lines
modified:src/jsx/hooks/index.ts+2 added-2 removed
368 unmodified lines
369 return { current: null }370}371372export const forwardRef = <T, P = {}>(373 Component: (props: P, ref: RefObject<T>) => JSX.Element374): ((props: P & { ref: RefObject<T> }) => JSX.Element) => {373 Component: (props: P, ref?: RefObject<T>) => JSX.Element374): ((props: P & { ref?: RefObject<T> }) => JSX.Element) => {375 return (props) => {376 const { ref, ...rest } = props377 return Component(rest as P, ref)378 }
44 unmodified lines