@@ -2,15 +2,16 @@ import * as React from 'react';
2
2
3
3
import render from './render' ;
4
4
import renderAsync from './render-async' ;
5
+ import type { RefObject } from './types' ;
5
6
6
7
export type RenderHookResult < Result , Props > = {
7
- result : React . RefObject < Result > ;
8
+ result : RefObject < Result > ;
8
9
rerender : ( props : Props ) => void ;
9
10
unmount : ( ) => void ;
10
11
} ;
11
12
12
13
export type RenderHookAsyncResult < Result , Props > = {
13
- result : React . RefObject < Result > ;
14
+ result : RefObject < Result > ;
14
15
rerenderAsync : ( props : Props ) => Promise < void > ;
15
16
unmountAsync : ( ) => Promise < void > ;
16
17
} ;
@@ -39,7 +40,7 @@ export function renderHook<Result, Props>(
39
40
hookToRender : ( props : Props ) => Result ,
40
41
options ?: RenderHookOptions < Props > ,
41
42
) : RenderHookResult < Result , Props > {
42
- const result : React . RefObject < Result | null > = React . createRef ( ) ;
43
+ const result = React . createRef < Result > ( ) as RefObject < Result > ;
43
44
44
45
function HookContainer ( { hookProps } : { hookProps : Props } ) {
45
46
const renderResult = hookToRender ( hookProps ) ;
@@ -58,8 +59,7 @@ export function renderHook<Result, Props>(
58
59
) ;
59
60
60
61
return {
61
- // Result should already be set after the first render effects are run.
62
- result : result as React . RefObject < Result > ,
62
+ result : result ,
63
63
rerender : ( hookProps : Props ) => rerenderComponent ( < HookContainer hookProps = { hookProps } /> ) ,
64
64
unmount,
65
65
} ;
@@ -69,7 +69,7 @@ export async function renderHookAsync<Result, Props>(
69
69
hookToRender : ( props : Props ) => Result ,
70
70
options ?: RenderHookOptions < Props > ,
71
71
) : Promise < RenderHookAsyncResult < Result , Props > > {
72
- const result : React . RefObject < Result | null > = React . createRef ( ) ;
72
+ const result = React . createRef < Result > ( ) as RefObject < Result > ;
73
73
74
74
function TestComponent ( { hookProps } : { hookProps : Props } ) {
75
75
const renderResult = hookToRender ( hookProps ) ;
@@ -88,8 +88,7 @@ export async function renderHookAsync<Result, Props>(
88
88
) ;
89
89
90
90
return {
91
- // Result should already be set after the first render effects are run.
92
- result : result as React . RefObject < Result > ,
91
+ result : result ,
93
92
rerenderAsync : ( hookProps : Props ) =>
94
93
rerenderComponentAsync ( < TestComponent hookProps = { hookProps } /> ) ,
95
94
unmountAsync,
0 commit comments