Skip to content

Commit 18c3c8b

Browse files
committed
Added basic Usage docs. Fixes #4
1 parent 7f78b5a commit 18c3c8b

File tree

3 files changed

+109
-28
lines changed

3 files changed

+109
-28
lines changed

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,27 @@ npm install react-hooks-testing-library
119119

120120
## Usage
121121

122-
```js
123-
// TODO: write this - see Example above for now
124-
```
122+
### `renderHook(callback[, options])`
123+
124+
Renders a test component that will call the provided `callback`, including any hooks it contains, every time it renders.
125+
126+
> _Note: `testHook` has been renamed to `renderHook`. `testHook` will continue work in the current version with a deprecation warning, but will be removed in a future version._
127+
>
128+
> **_You should update an usages of `testHook` to use `renderHook` instead._**
129+
130+
#### Arguments
131+
132+
- `callback` (`function()`) - function to call each render. This function should call one or more hooks for testing.
133+
- `options` (`object`):
134+
- `initialProps` (`object`) - the initial values to pass to the `callback` function
135+
- `wrapper` (`Component`) - A component to wrap the underlying test component, commonly used to add context providers for the `useContext` hook. The component will recieve the test component as `children` and must render it.
136+
137+
#### Returns
138+
139+
- `result` (`object`)
140+
- `current` (`any`) - the return value of the `callback` function
141+
- `rerender` (`function([newProps])`) - function to rerender the test component including any hooks called in the `callback` function. If `newProps` are passed, the will replace the `initialProps` passed the the `callback` function for future renders.
142+
- `unmount` (`function()`) - function to unmount the test component, commonly used to trigger cleanup effects for `useEffect` hooks.
125143

126144
## Contributors
127145

package-lock.json

+84-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"contributors:add": "all-contributors add"
1818
},
1919
"dependencies": {
20-
"react-testing-library": "^5.9.0"
20+
"react-testing-library": "^6.0.0"
2121
},
2222
"devDependencies": {
2323
"@babel/cli": "^7.2.3",
@@ -26,7 +26,7 @@
2626
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
2727
"@babel/preset-env": "^7.3.1",
2828
"@babel/preset-react": "^7.0.0",
29-
"all-contributors-cli": "^6.1.1",
29+
"all-contributors-cli": "^6.1.2",
3030
"babel-eslint": "^10.0.1",
3131
"babel-plugin-module-resolver": "^3.2.0",
3232
"eslint": "^5.14.1",
@@ -38,8 +38,8 @@
3838
"prettier": "^1.16.4",
3939
"prettier-eslint": "^8.8.2",
4040
"prettier-eslint-cli": "^4.7.1",
41-
"react": "^16.8.2",
42-
"react-dom": "^16.8.2"
41+
"react": "^16.8.3",
42+
"react-dom": "^16.8.3"
4343
},
4444
"peerDependencies": {
4545
"react": "^16.8.0",

0 commit comments

Comments
 (0)