|
| 1 | +--- |
| 2 | +name: Renderer |
| 3 | +route: '/renderer' |
| 4 | +--- |
| 5 | + |
| 6 | +# Render Engine |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +React requires a rendering engine, typically when creating an application people use `react-dom`. |
| 11 | +When running tests, React still requires an engine. We currently support two different engines – |
| 12 | +`react-test-renderer` & `react-dom`. If you have both installed in your project, by default we will |
| 13 | +use `react-test-renderer`, assuming you're using the default imports: |
| 14 | + |
| 15 | +```js |
| 16 | +import { renderHook } from '@testing-library/react-hooks' |
| 17 | +``` |
| 18 | + |
| 19 | +It does this because the library runs a check for available renderers, in the order: |
| 20 | + |
| 21 | +- `react-test-renderer` |
| 22 | +- `react-dom` |
| 23 | + |
| 24 | +If neither are available you will see an error asking you to check that one of the above is |
| 25 | +installed. If only one is installed, then it will use that renderer. |
| 26 | + |
| 27 | +## Being specific |
| 28 | + |
| 29 | +If, however, for certain tests you want to use a specific renderer (e.g. you want to use `react-dom` |
| 30 | +for SSR) you can import the server module directly: |
| 31 | + |
| 32 | +```ts |
| 33 | +import { renderHook } from '@testing-library/react-hooks/server` |
| 34 | +``` |
| 35 | + |
| 36 | +We have the following exports available: |
| 37 | + |
| 38 | +```ts |
| 39 | +import { renderHook, act } from '@testing-library/react-hooks' // will try to auto-detect |
| 40 | +
|
| 41 | +import { renderHook, act } from '@testing-library/react-hooks/dom' // will use react-dom |
| 42 | +
|
| 43 | +import { renderHook, act } from '@testing-library/react-hooks/native' // will use react-test-renderer |
| 44 | +
|
| 45 | +import { renderHook, act } from '@testing-library/react-hooks/server' // will use react-dom |
| 46 | +``` |
| 47 | +
|
| 48 | +## Caveats |
| 49 | +
|
| 50 | +### SSR |
| 51 | +
|
| 52 | +While calling `renderHook` from `@testing-library/react-hooks/native` and |
| 53 | +`@testing-library/react-hooks/dom` will return the same `RenderHookResult` as documented |
| 54 | +[here](/reference/api#renderhook-result), using `@testing-library/react-hooks/server` will return an |
| 55 | +additional function: |
| 56 | +
|
| 57 | +```ts |
| 58 | +hydrate: () => void |
| 59 | +``` |
| 60 | + |
| 61 | +For more information on `hydrate` see the [API documentation](/reference/api#hydrate) |
0 commit comments