@nutui/nutui-react-taro
Version:
京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序
20 lines (19 loc) • 376 B
JavaScript
import { useRef } from "react";
const idCounter = {};
function uniqueId(prefix = "$nut$") {
if (!idCounter[prefix]) {
idCounter[prefix] = 0;
}
const id = ++idCounter[prefix];
if (prefix === "$nut$") {
return `${id}`;
}
return `${prefix}${id}`;
}
function useUuid() {
const idRef = useRef(uniqueId());
return idRef.current;
}
export {
useUuid as u
};