@@ -11,16 +11,14 @@ route: '/reference/api'
1111- [ ` act ` ] ( /reference/api#act )
1212- [ ` cleanup ` ] ( /reference/api#cleanup )
1313- [ ` addCleanup ` ] ( /reference/api#addcleanup )
14+ - [ ` removeCleanup ` ] ( /reference/api#removecleanup )
1415
1516---
1617
1718## ` renderHook `
1819
19- ``` js
20- function renderHook (
21- callback : function (props ?: any ): any,
22- options?: RenderHookOptions
23- ): RenderHookResult
20+ ``` ts
21+ function renderHook(callback : (props ? : any ) => any , options ? : RenderHookOptions ): RenderHookResult
2422```
2523
2624Renders a test component that will call the provided ` callback ` , including any hooks it calls , every
@@ -61,7 +59,7 @@ The `renderHook` function returns an object that has the following properties:
6159
6260### ` result `
6361
64- ```js
62+ ` ` ` ts
6563{
6664 all: Array<any>
6765 current: any,
@@ -77,7 +75,7 @@ returned at the time.
7775
7876### ` rerender `
7977
80- ` ` ` js
78+ ` ` ` ts
8179function rerender(newProps?: any): void
8280` ` `
8381
@@ -86,13 +84,27 @@ passed, they will replace the `callback` function's `initialProps` for subsequen
8684
8785### ` unmount `
8886
89- ```js
87+ ` ` ` ts
9088function unmount(): void
9189` ` `
9290
9391A function to unmount the test component. This is commonly used to trigger cleanup effects for
9492`useEffect` hooks.
9593
94+ ### ` hydrate `
95+
96+ ` ` ` ts
97+ function hydrate(): void
98+ ` ` `
99+
100+ > This is only used when using the ` server ` module . See [SSR ](/ usage / ssr ) for more information on
101+ > server - side rendering your hooks .
102+
103+ A function to hydrate a server rendered component into the DOM. This is required before you can
104+ interact with the hook, whether that is an `act` or `rerender` call. Effects created using
105+ `useEffect` or `useLayoutEffect` are also not run on server rendered hooks until `hydrate` is
106+ called.
107+
96108### ` ...asyncUtils `
97109
98110Utilities to assist with testing asynchronous behaviour . See the
@@ -102,15 +114,15 @@ Utilities to assist with testing asynchronous behaviour. See the
102114
103115## ` act `
104116
105- This is the same [`act` function](https:// reactjs.org/docs/test-utils.html#act) that is exported by
106- `react-test- renderer` .
117+ This is the same [` act ` function ](https : // reactjs.org/docs/test-utils.html#act) function that is
118+ exported from your [ chosen renderer ](/ installation # renderer ) .
107119
108120---
109121
110122## ` cleanup `
111123
112- ```js
113- function cleanup: Promise<void>
124+ ` ` ` ts
125+ function cleanup() : Promise<void>
114126` ` `
115127
116128Unmounts any rendered hooks rendered with ` renderHook ` , ensuring all effects have been flushed. Any
@@ -142,7 +154,8 @@ module.exports = {
142154` ` `
143155
144156Alternatively , you can change your test to import from ` @testing-library/react-hooks/pure ` instead
145- of the regular imports.
157+ of the regular imports. This applys to any of our export methods documented in
158+ [Rendering ](/installation #being -specific ).
146159
147160` ` ` diff
148161- import { renderHook, cleanup, act } from '@testing-library/react-hooks'
@@ -156,8 +169,8 @@ variable to `true` before importing `@testing-library/react-hooks` will also dis
156169
157170## ` addCleanup `
158171
159- ` ` ` js
160- function addCleanup (callback : function (): void| Promise<void>): function (): void
172+ ` ` ` ts
173+ function addCleanup(callback: () => void | Promise<void>): (): void
161174` ` `
162175
163176Add a callback to be called during [` cleanup ` ](/reference /api #cleanup ), returning a function to
@@ -173,8 +186,8 @@ be resolved before moving onto the next cleanup callback.
173186
174187## `removeCleanup`
175188
176- ```js
177- function removeCleanup(callback: function(): void| Promise<void>): void
189+ ```ts
190+ function removeCleanup(callback : () => void | Promise <void >): void
178191```
179192
180193Removes a cleanup callback previously added with [`addCleanup`](/reference /api #addCleanup ). Once
@@ -187,10 +200,8 @@ removed, the provided callback will no longer execute as part of running
187200
188201### `waitForNextUpdate`
189202
190- ```js
191- function waitForNextUpdate(options?: {
192- timeout?: number
193- }): Promise<void>
203+ ```ts
204+ function waitForNextUpdate(options ? : { timeout? : number }): Promise <void >
194205```
195206
196207Returns a `Promise` that resolves the next time the hook renders, commonly when state is updated as
@@ -202,12 +213,15 @@ The maximum amount of time in milliseconds (ms) to wait. By default, no timeout
202213
203214### `waitFor`
204215
205- ```js
206- function waitFor(callback: function(): boolean|void, options?: {
207- interval?: number,
208- timeout?: number,
209- suppressErrors?: boolean
210- }): Promise<void>
216+ ```ts
217+ function waitFor(
218+ callback : () => boolean | void ,
219+ options ? : {
220+ interval? : number
221+ timeout? : number
222+ suppressErrors? : boolean
223+ }
224+ ): Promise <void >
211225```
212226
213227Returns a `Promise` that resolves if the provided callback executes without exception and returns a
@@ -232,12 +246,15 @@ rejected. By default, errors are suppressed for this utility.
232246
233247### `waitForValueToChange`
234248
235- ```js
236- function waitForValueToChange(selector: function(): any, options?: {
237- interval?: number,
238- timeout?: number,
239- suppressErrors?: boolean
240- }): Promise < void >
249+ ```ts
250+ function waitForValueToChange(
251+ selector : () => any ,
252+ options ? : {
253+ interval? : number
254+ timeout? : number
255+ suppressErrors? : boolean
256+ }
257+ ): Promise <void >
241258```
242259
243260Returns a `Promise` that resolves if the value returned from the provided selector changes. It is
0 commit comments