use-nanoid
v1.1.0
Published
React hook to generate a random ID using nanoid
Downloads
14
Maintainers
Readme
use-nanoid
React hook to generate a random ID using nanoid
Table of Contents
About
Simple hook to generate an ID using nanoid. If you need SSR, use @reach/auto-id.
Usage
import React from "react";
import {useNanoid} from 'use-nanoid'
export default function App() {
const id = useNanoid()
const otherId = useNanoid(10) // Length of ID
const yeahId = useNanoid('1000') // Use provided string as ID
return (
<div>
<h1>{id}</h1>
<h2>{otherId}</h2>
<h3>{yeahId}</h3>
</div>
);
}
Install
This project uses node and npm.
$ npm install use-nanoid
$ # OR
$ yarn add use-nanoid
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
mit