use-nanoid

React hook to generate a random ID using nanoid

Usage no npm install needed!

<script type="module">
  import useNanoid from 'https://cdn.skypack.dev/use-nanoid';
</script>

README

use-nanoid

package version package downloads standard-readme compliant package license make a pull request

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

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

mit