@@ -2,15 +2,16 @@ import * as React from 'react';
22
33import render from './render' ;
44import renderAsync from './render-async' ;
5+ import type { RefObject } from './types' ;
56
67export type RenderHookResult < Result , Props > = {
7- result : React . RefObject < Result > ;
8+ result : RefObject < Result > ;
89 rerender : ( props : Props ) => void ;
910 unmount : ( ) => void ;
1011} ;
1112
1213export type RenderHookAsyncResult < Result , Props > = {
13- result : React . RefObject < Result > ;
14+ result : RefObject < Result > ;
1415 rerenderAsync : ( props : Props ) => Promise < void > ;
1516 unmountAsync : ( ) => Promise < void > ;
1617} ;
@@ -39,7 +40,7 @@ export function renderHook<Result, Props>(
3940 hookToRender : ( props : Props ) => Result ,
4041 options ?: RenderHookOptions < Props > ,
4142) : RenderHookResult < Result , Props > {
42- const result : React . RefObject < Result | null > = React . createRef ( ) ;
43+ const result = React . createRef < Result > ( ) as RefObject < Result > ;
4344
4445 function HookContainer ( { hookProps } : { hookProps : Props } ) {
4546 const renderResult = hookToRender ( hookProps ) ;
@@ -58,8 +59,7 @@ export function renderHook<Result, Props>(
5859 ) ;
5960
6061 return {
61- // Result should already be set after the first render effects are run.
62- result : result as React . RefObject < Result > ,
62+ result : result ,
6363 rerender : ( hookProps : Props ) => rerenderComponent ( < HookContainer hookProps = { hookProps } /> ) ,
6464 unmount,
6565 } ;
@@ -69,7 +69,7 @@ export async function renderHookAsync<Result, Props>(
6969 hookToRender : ( props : Props ) => Result ,
7070 options ?: RenderHookOptions < Props > ,
7171) : Promise < RenderHookAsyncResult < Result , Props > > {
72- const result : React . RefObject < Result | null > = React . createRef ( ) ;
72+ const result = React . createRef < Result > ( ) as RefObject < Result > ;
7373
7474 function TestComponent ( { hookProps } : { hookProps : Props } ) {
7575 const renderResult = hookToRender ( hookProps ) ;
@@ -88,8 +88,7 @@ export async function renderHookAsync<Result, Props>(
8888 ) ;
8989
9090 return {
91- // Result should already be set after the first render effects are run.
92- result : result as React . RefObject < Result > ,
91+ result : result ,
9392 rerenderAsync : ( hookProps : Props ) =>
9493 rerenderComponentAsync ( < TestComponent hookProps = { hookProps } /> ) ,
9594 unmountAsync,
0 commit comments