Skip to content

Commit 7481d77

Browse files
committed
docs: create installation page and remove SSR to be in own page
1 parent 71762aa commit 7481d77

File tree

4 files changed

+82
-101
lines changed

4 files changed

+82
-101
lines changed

docs/installation.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
name: Installation
3+
route: '/installation'
4+
---
5+
6+
# Installation
7+
8+
## Getting started
9+
10+
This module is distributed via [npm](https://www.npmjs.com/) which is bundled with
11+
[node](https://nodejs.org) and should be installed as one of your project's `devDependencies`:
12+
13+
```sh
14+
# if you're using npm
15+
npm install --save-dev @testing-library/react-hooks
16+
# if you're using yarn
17+
yarn add --dev @testing-library/react-hooks
18+
```
19+
20+
### Peer Dependencies
21+
22+
`react-hooks-testing-library` does not come bundled with a version of
23+
[`react`](https://www.npmjs.com/package/react) to allow you to install the specific version you want
24+
to test against. It also does not come installed with a specific renderer, we currently support
25+
[`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer) and
26+
[`react-dom`](https://www.npmjs.com/package/react-dom), you only need to install one of them. For
27+
more information see [Renderer](/installation#renderer)
28+
29+
```sh
30+
npm install react@^16.9.0
31+
npm install --save-dev react-test-renderer@^16.9.0
32+
```
33+
34+
> **NOTE: The minimum supported version of `react`, `react-test-renderer` and `react-dom` is
35+
> `^16.9.0`.**
36+
37+
## Renderer
38+
39+
React requires a rendering engine, typically when creating an application people use `react-dom`.
40+
When running tests, React still requires an engine. We currently support two different engines:
41+
42+
- `react-test-renderer`
43+
- `react-dom`
44+
45+
If you have both installed in your project, assuming you're using the default imports (see below)
46+
the library defaults to using `react-test-renderer`. This is because rtr is the defacto test
47+
renderer for `react-native` for tests and it enables hooks to be correctly tested that are written
48+
for both `react` & `react-native`.
49+
50+
```js
51+
import { renderHook } from '@testing-library/react-hooks'
52+
```
53+
54+
> The auto detection function may not work if tests are bundled to run in the browser.
55+
56+
## Being specific
57+
58+
If, however, for certain tests you want to use a specific renderer (e.g. you want to use `react-dom`
59+
for SSR) you can import the server module directly:
60+
61+
```ts
62+
import { renderHook } from '@testing-library/react-hooks/server`
63+
```
64+
65+
We have the following exports available:
66+
67+
```ts
68+
import { renderHook, act } from '@testing-library/react-hooks' // will try to auto-detect
69+
70+
import { renderHook, act } from '@testing-library/react-hooks/dom' // will use react-dom
71+
72+
import { renderHook, act } from '@testing-library/react-hooks/native' // will use react-test-renderer
73+
74+
import { renderHook, act } from '@testing-library/react-hooks/server' // will use react-dom
75+
```
76+
77+
## Testing Framework
78+
79+
In order to run tests, you will probably want to be using a test framework. If you have not already
80+
got one, we recommend using [Jest](https://jestjs.io/), but this library should work without issues
81+
with any of the alternatives.

docs/introduction.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,3 @@ the results.
5555

5656
1. Your hook is defined alongside a component and is only used there
5757
2. Your hook is easy to test by just testing the components using it
58-
59-
## Installation
60-
61-
This module is distributed via [npm](https://www.npmjs.com/) which is bundled with
62-
[node](https://nodejs.org) and should be installed as one of your project's `devDependencies`:
63-
64-
```sh
65-
npm install --save-dev @testing-library/react-hooks
66-
```
67-
68-
### Peer Dependencies
69-
70-
`react-hooks-testing-library` does not come bundled with a version of
71-
[`react`](https://www.npmjs.com/package/react) to allow you to install the specific version you want
72-
to test against. It also does not come installed with a specific renderer, we currently support
73-
[`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer) and
74-
[`react-dom`](https://www.npmjs.com/package/react-dom), you only need to install one of them.
75-
However,you can install both, but `react-test-renderer` is the default, for more information see the
76-
[installation docs](https://react-hooks-testing-library.com/#installation). Generally, the installed
77-
versions for `react` and the selected renderer should have matching versions:
78-
79-
```sh
80-
npm install react@^16.9.0
81-
npm install --save-dev react-test-renderer@^16.9.0
82-
```
83-
84-
> **NOTE: The minimum supported version of `react`, `react-test-renderer` and `react-dom` is
85-
> `^16.9.0`.**
86-
87-
## Testing Framework
88-
89-
In order to run tests, you will probably want to be using a test framework. If you have not already
90-
got one, we recommend using [Jest](https://jestjs.io/), but this library should work without issues
91-
with any of the alternatives.

docs/renderer.md

Lines changed: 0 additions & 66 deletions
This file was deleted.

doczrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default {
1818
},
1919
menu: [
2020
{ name: 'Introduction' },
21+
{ name: 'Installation' },
2122
{ name: 'Usage', menu: ['Basic Hooks', 'Advanced Hooks'] },
22-
{ name: 'Renderer' },
2323
{ name: 'API Reference' }
2424
]
2525
}

0 commit comments

Comments
 (0)