1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
4 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = void 0;
|
9 | exports.resetUuid = resetUuid;
|
10 | var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
11 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
12 | var React = _interopRequireWildcard(require("react"));
|
13 | function getUseId() {
|
14 |
|
15 | var fullClone = (0, _objectSpread2.default)({}, React);
|
16 | return fullClone.useId;
|
17 | }
|
18 | var uuid = 0;
|
19 |
|
20 |
|
21 | function resetUuid() {
|
22 | if (process.env.NODE_ENV !== 'production') {
|
23 | uuid = 0;
|
24 | }
|
25 | }
|
26 | var useOriginId = getUseId();
|
27 | var _default = exports.default = useOriginId ?
|
28 |
|
29 | function useId(id) {
|
30 | var reactId = useOriginId();
|
31 |
|
32 |
|
33 | if (id) {
|
34 | return id;
|
35 | }
|
36 |
|
37 |
|
38 | if (process.env.NODE_ENV === 'test') {
|
39 | return 'test-id';
|
40 | }
|
41 | return reactId;
|
42 | } :
|
43 |
|
44 | function useCompatId(id) {
|
45 |
|
46 | var _React$useState = React.useState('ssr-id'),
|
47 | _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
48 | innerId = _React$useState2[0],
|
49 | setInnerId = _React$useState2[1];
|
50 | React.useEffect(function () {
|
51 | var nextId = uuid;
|
52 | uuid += 1;
|
53 | setInnerId("rc_unique_".concat(nextId));
|
54 | }, []);
|
55 |
|
56 |
|
57 | if (id) {
|
58 | return id;
|
59 | }
|
60 |
|
61 |
|
62 | if (process.env.NODE_ENV === 'test') {
|
63 | return 'test-id';
|
64 | }
|
65 |
|
66 |
|
67 | return innerId;
|
68 | }; |
\ | No newline at end of file |