Skip to content

Commit 5a45abf

Browse files
committed
render hook
1 parent a47fd8f commit 5a45abf

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

website/docs/14.x/docs/api/misc/render-hook.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ async function renderHook<Result, Props>(
99
): Promise<RenderHookResult<Result, Props>>;
1010
```
1111

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.
1313

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.
1515

1616
- **Returns a Promise**: Should be awaited
1717
- **Async methods**: Both `rerender` and `unmount` return Promises and should be awaited
@@ -47,21 +47,21 @@ export const useCount = () => {
4747

4848
The `renderHook` function accepts the following arguments:
4949

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.
5151

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.
5353

5454
### `options`
5555

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:
5757

5858
#### `initialProps` {#initial-props}
5959

6060
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.
6161

6262
#### `wrapper`
6363

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`.
6565

6666
### Result
6767

@@ -77,13 +77,13 @@ The `renderHook` function returns a Promise that resolves to an object with the
7777

7878
#### `result`
7979

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.
8181

8282
**Note:** When using React Suspense, `result.current` will be `null` while the hook is suspended.
8383

8484
#### `rerender`
8585

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.
8787

8888
**Note**: This method returns a Promise and should be awaited.
8989

@@ -95,7 +95,7 @@ An async function to unmount the test component. This is commonly used to trigge
9595

9696
### Examples
9797

98-
Here we present some extra examples of using `renderHook` API.
98+
Additional examples of using `renderHook`:
9999

100100
#### With `initialProps`
101101

0 commit comments

Comments
 (0)