Skip to content

Commit

Permalink
Merge pull request streamich#332 from streamich/docs-usage
Browse files Browse the repository at this point in the history
docs: ✏️ move usage docs into its own file
  • Loading branch information
streamich authored May 31, 2019
2 parents 619a470 + c2b153f commit 8e11b7c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
43 changes: 16 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,25 @@
- [`useList`](./docs/useList.md) — tracks state of an array.
- [`useMap`](./docs/useMap.md) — tracks state of an object.

## Usage

You need to have React [`16.8.0`](https://reactjs.org/blog/2019/02/06/react-v16.8.0.html) or later installed to use the Hooks API. You can import each hook individually

```js
import useToggle from 'react-use/lib/useToggle'
```

or use ES6 named imports

```js
import {useToggle} from 'react-use'
```

Depending on your bundler you might run into a missing dependency error with ES6 named import statements. Some hooks require you to install peer dependencies so we recommend using individual imports. If you want the best of both worlds you can transform the named import statements to individual import statements with [`babel-plugin-import`](https://github.com/ant-design/babel-plugin-import) by adding the following config to your `.babelrc` file:

```json
[
"import", {
"libraryName": "react-use",
"libraryDirectory": "lib",
"camel2DashComponentName": false
}
]
```

<h2 align="center"><sub>License</sub></h2>
<br />
<br />
<br />
<br />
<br />
<br />
<br />

<p align="center">
<a href="./LICENSE">Unlicense</a> &mdash; public domain.
<a href="./docs/Usage.md"><strong>Usage</strong></a> &mdash; how to import.
<br />
<a href="./LICENSE"><strong>Unlicense</strong></a> &mdash; public domain.
</p>

<br />
<br />
<br />
<br />
<br />

[img-demo]: https://img.shields.io/badge/demo-%20%20%20%F0%9F%9A%80-green.svg
25 changes: 25 additions & 0 deletions docs/Usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Usage

You need to have React [`16.8.0`](https://reactjs.org/blog/2019/02/06/react-v16.8.0.html) or later installed to use the Hooks API. You can import each hook individually

```js
import useToggle from 'react-use/lib/useToggle'
```

or use ES6 named imports

```js
import {useToggle} from 'react-use'
```

Depending on your bundler you might run into a missing dependency error with ES6 named import statements. Some hooks require you to install peer dependencies so we recommend using individual imports. If you want the best of both worlds you can transform the named import statements to individual import statements with [`babel-plugin-import`](https://github.com/ant-design/babel-plugin-import) by adding the following config to your `.babelrc` file:

```json
[
"import", {
"libraryName": "react-use",
"libraryDirectory": "lib",
"camel2DashComponentName": false
}
]
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
},
"homepage": "https://github.com/streamich/react-use#readme",
"dependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"babel-plugin-dynamic-import-node": "^2.2.0",
"copy-to-clipboard": "^3.1.0",
"nano-css": "^5.1.0",
"react-fast-compare": "^2.0.4",
Expand All @@ -65,6 +63,8 @@
"@babel/preset-env": "7.4.5",
"@babel/preset-react": "7.0.0",
"@babel/preset-typescript": "7.3.3",
"@babel/plugin-syntax-dynamic-import": "7.2.0",
"babel-plugin-dynamic-import-node": "^2.2.0",
"@semantic-release/changelog": "3.0.2",
"@semantic-release/git": "7.0.8",
"@semantic-release/npm": "5.1.7",
Expand Down

0 comments on commit 8e11b7c

Please sign in to comment.