Robin Pokorny
1 min readJul 22, 2018

--

Hi Barsum,

You are right, shortid and Math.random are the same for our purposes.

The important distinction, whether it is an anti-pattern or it is actually OK to use, is where you call it.

Math.random or shortid is an anti-pattern if you call it in the render function. Then, a new value is assigned every time a re-render happens.

If you assign a random id value which is somehow persisted, which I describe in the article, it is OK to use it.

But please always look if there is no other value you could use as an id.

Regarding the string, if it is unique to the item, you can use it as it is, no need for hash.

--

--

Robin Pokorny
Robin Pokorny

Written by Robin Pokorny

Architecture & Tech Leadership — Speaks — Loves maths — Reads specs — Podcasts — Lives in Berlin — robinpokorny.com

No responses yet