You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/14.x/docs/api/misc/render-hook.mdx
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,9 @@ async function renderHook<Result, Props>(
9
9
):Promise<RenderHookResult<Result, Props>>;
10
10
```
11
11
12
-
Renders a test component that will call the provided `callback`, including any hooks it calls, every time it renders. Returns a Promise that resolves to a [`RenderHookResult`](#renderhookresult) object, which you can interact with.
12
+
Renders a test component that calls the provided `callback` (and any hooks it uses) on each render. Returns a Promise that resolves to a [`RenderHookResult`](#renderhookresult) object.
13
13
14
-
**This is the recommended default API** for testing hooks. It uses async `act` internally to ensure all pending React updates are executed during rendering, making it compatible with async React features like `Suspense`boundary or`use()` hook.
14
+
**This is the recommended default API** for testing hooks. It uses async `act` internally to ensure all pending React updates are executed during rendering. This makes it compatible with async React features like `Suspense`boundaries and the`use()` hook.
15
15
16
16
-**Returns a Promise**: Should be awaited
17
17
-**Async methods**: Both `rerender` and `unmount` return Promises and should be awaited
The `renderHook` function accepts the following arguments:
49
49
50
-
Callback is a function that is called each `render` of the test component. This function should call one or more hooks for testing.
50
+
**Callback**: A function called on each render of the test component. This function should call one or more hooks for testing.
51
51
52
-
The `props` passed into the callback will be the `initialProps` provided in the `options` to `renderHook`, unless new props are provided by a subsequent `rerender` call.
52
+
The callback receives `props` from the `initialProps` option, or from a subsequent `rerender` call if provided.
53
53
54
54
### `options`
55
55
56
-
A `RenderHookOptions<Props>` object to modify the execution of the `callback` function, containing the following properties:
56
+
A `RenderHookOptions<Props>` object with the following properties:
57
57
58
58
#### `initialProps`{#initial-props}
59
59
60
60
The initial values to pass as `props` to the `callback` function of `renderHook`. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
61
61
62
62
#### `wrapper`
63
63
64
-
A React component to wrap the test component in when rendering. This is usually used to add context providers from `React.createContext` for the hook to access with `useContext`.
64
+
A React component that wraps the test component. Use this to add context providers so hooks can access them with `useContext`.
65
65
66
66
### Result
67
67
@@ -77,13 +77,13 @@ The `renderHook` function returns a Promise that resolves to an object with the
77
77
78
78
#### `result`
79
79
80
-
The `current` value of the `result` will reflect the latest of whatever is returned from the `callback`passed to`renderHook`. The `Result` type is determined by the type passed to or inferred by the `renderHook` call.
80
+
The `current` value contains whatever the `callback`returned from`renderHook`. The `Result` type is determined by the type passed to or inferred by the `renderHook` call.
81
81
82
82
**Note:** When using React Suspense, `result.current` will be `null` while the hook is suspended.
83
83
84
84
#### `rerender`
85
85
86
-
An async function to rerender the test component, causing any hooks to be recalculated. If `newProps` are passed, they will replace the `callback` function's `initialProps` for subsequent rerenders. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
86
+
An async function that rerenders the test component and recalculates hooks. If `newProps` are passed, they replace the `callback` function's `initialProps` for subsequent rerenders. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
87
87
88
88
**Note**: This method returns a Promise and should be awaited.
89
89
@@ -95,7 +95,7 @@ An async function to unmount the test component. This is commonly used to trigge
95
95
96
96
### Examples
97
97
98
-
Here we present some extra examples of using `renderHook` API.
0 commit comments