UNPKG

weak-key

Version:

get a unique key for an object ( mainly for react's key={} )

13 lines (11 loc) 209 B
var map = new WeakMap(); var index = 0; module.exports = weakKey; function weakKey(obj) { var key = map.get(obj); if (!key) { key = 'weak-key-' + index++; map.set(obj, key); } return key; }