MCPcopy
hub / github.com/testing-library/react-hooks-testing-library / renderHook

Function renderHook

src/core/index.ts:49–80  ·  view source on GitHub ↗
(
    callback: (props: TProps) => TResult,
    options = {} as RenderHookOptions<TProps> & TRendererOptions
  )

Source from the content-addressed store, hash-verified

47 TRenderer extends Renderer<TProps>
48>(createRenderer: CreateRenderer<TProps, TResult, TRendererOptions, TRenderer>) {
49 const renderHook = (
50 callback: (props: TProps) => TResult,
51 options = {} as RenderHookOptions<TProps> & TRendererOptions
52 ) => {
53 const { result, setValue, setError, addResolver } = resultContainer<TResult>()
54 const renderProps = { callback, setValue, setError }
55 let hookProps = options.initialProps
56
57 const { render, rerender, unmount, act, ...renderUtils } = createRenderer(renderProps, options)
58
59 render(hookProps)
60
61 const rerenderHook = (newProps = hookProps) => {
62 hookProps = newProps
63 rerender(hookProps)
64 }
65
66 const unmountHook = () => {
67 removeCleanup(unmountHook)
68 unmount()
69 }
70
71 addCleanup(unmountHook)
72
73 return {
74 result,
75 rerender: rerenderHook,
76 unmount: unmountHook,
77 ...asyncUtils(act, addResolver),
78 ...renderUtils
79 }
80 }
81
82 return renderHook
83}

Callers

nothing calls this directly

Calls 4

addCleanupFunction · 0.90
asyncUtilsFunction · 0.90
resultContainerFunction · 0.85
renderFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…