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/13.x/docs/api/misc/render-hook.mdx
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# `renderHook` function
2
2
3
+
## `renderHook`
4
+
3
5
```ts
4
6
function renderHook<Result, Props>(
5
7
hookFn: (props?:Props) =>Result,
@@ -41,15 +43,15 @@ Callback is a function that is called each `render` of the test component. This
41
43
42
44
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.
43
45
44
-
## `options`
46
+
###`options`
45
47
46
48
A `RenderHookOptions<Props>` object to modify the execution of the `callback` function, containing the following properties:
47
49
48
-
### `initialProps`{#initial-props}
50
+
####`initialProps`{#initial-props}
49
51
50
52
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.
51
53
52
-
### `wrapper`
54
+
####`wrapper`
53
55
54
56
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`.
55
57
@@ -58,7 +60,7 @@ A React component to wrap the test component in when rendering. This is usually
58
60
Set to `false` to disable concurrent rendering.
59
61
Otherwise, `render` will default to using concurrent rendering used in the React Native New Architecture.
The `renderHook` function returns an object that has the following properties:
72
74
73
-
### `result`
75
+
####`result`
74
76
75
77
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.
76
78
77
-
### `rerender`
79
+
####`rerender`
78
80
79
81
A 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.
80
82
81
-
### `unmount`
83
+
####`unmount`
82
84
83
85
A function to unmount the test component. This is commonly used to trigger cleanup effects for `useEffect` hooks.
84
86
85
-
## Examples
87
+
###Examples
86
88
87
89
Here we present some extra examples of using `renderHook` API.
0 commit comments