Skip to content

Instantly share code, notes, and snippets.

@csenio
Created October 28, 2019 14:51
Show Gist options
  • Save csenio/0dda8c9f45d4ec97b0a868b2fcd94f0a to your computer and use it in GitHub Desktop.
Save csenio/0dda8c9f45d4ec97b0a868b2fcd94f0a to your computer and use it in GitHub Desktop.
import {useState, useEffect} from 'react'
let _id = 0
const genId = () => ++_id
export default function useId() {
const [id, setId] = useState(null)
useEffect(() => setId(genId()), [])
return id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment