Skip to content

Commit

Permalink
Adding example for react using hooks (#159)
Browse files Browse the repository at this point in the history
* Adding example for react using hooks

This helps to understand how to use nanoid in react with hooks.

* using state instead of ref.
  • Loading branch information
nahumzs authored and ai committed Dec 14, 2019
1 parent c3ac1f4 commit 1ec3aa9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ This is good code. `this.id` will be generated only once:
}
```

or with hooks

```jsx
const [id] = React.useState(nanoid)
```

If you want to use Nano ID for `id`, you must to set some string prefix.
Nano ID could be started from number. HTML ID can’t be started from the number.

Expand Down

0 comments on commit 1ec3aa9

Please sign in to comment.