1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.useUIDSeed = exports.useUID = void 0;
|
4 | var React = require("react");
|
5 | var react_1 = require("react");
|
6 | var context_1 = require("./context");
|
7 | var generateUID = function (context) {
|
8 | var quartz = context || context_1.counter;
|
9 | var prefix = (0, context_1.getPrefix)(quartz);
|
10 | var id = (0, context_1.getId)(quartz);
|
11 | var uid = prefix + id;
|
12 | var gen = function (item) { return uid + quartz.uid(item); };
|
13 | return { uid: uid, gen: gen };
|
14 | };
|
15 | var useUIDState = function () {
|
16 | if (process.env.NODE_ENV !== 'production') {
|
17 | if (!('useContext' in React)) {
|
18 | throw new Error('Hooks API requires React 16.8+');
|
19 | }
|
20 | }
|
21 | var context = (0, react_1.useContext)(context_1.source);
|
22 | var uid = (0, react_1.useState)(function () { return generateUID(context); })[0];
|
23 | return uid;
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | var useUID = function () {
|
35 | var uid = useUIDState().uid;
|
36 | return uid;
|
37 | };
|
38 | exports.useUID = useUID;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | var useUIDSeed = function () {
|
54 | var gen = useUIDState().gen;
|
55 | return gen;
|
56 | };
|
57 | exports.useUIDSeed = useUIDSeed;
|