Skip to content

Commit

Permalink
Simplify React example
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Dec 14, 2019
1 parent 1ec3aa9 commit d3e9e67
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,15 @@ between renders. This is bad code:
<Item key={nanoid()} /> /* DON’T DO IT */
```

This is good code. `this.id` will be generated only once:
This is good code. `id` will be generated only once:

```jsx
id = nanoid()
render () {
return <Item key={this.id}>;
}
const Element = () => {
const [id] = React.useState(nanoid)
return <Item key={id}>
}
```

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 d3e9e67

Please sign in to comment.