Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Created June 25, 2021 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save honzabrecka/3c927ba83fa0d2c9e59f9262385e8eb7 to your computer and use it in GitHub Desktop.
Save honzabrecka/3c927ba83fa0d2c9e59f9262385e8eb7 to your computer and use it in GitHub Desktop.
let ix = 0;
const getIx = () => `generated_id/${ix++}`
const useGenerateId = () => {
const [id, setId] = useState(getIx);
const regenerate = useCallback(() => setId(getIx()), []);
return [id, regenerate];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment