24 lines
1.1 KiB
JavaScript
24 lines
1.1 KiB
JavaScript
|
define(["require", "exports", "react", "@fluentui/utilities"], function (require, exports, React, utilities_1) {
|
||
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.useId = void 0;
|
||
|
/**
|
||
|
* Hook to generate a unique ID in the global scope (spanning across duplicate copies of the same library).
|
||
|
*
|
||
|
* @param prefix - Optional prefix for the ID
|
||
|
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
||
|
* without conditioning the hook call
|
||
|
* @returns The ID
|
||
|
*/
|
||
|
function useId(prefix, providedId) {
|
||
|
// getId should only be called once since it updates the global constant for the next ID value.
|
||
|
// (While an extra update isn't likely to cause problems in practice, it's better to avoid it.)
|
||
|
var ref = React.useRef(providedId);
|
||
|
if (!ref.current) {
|
||
|
ref.current = (0, utilities_1.getId)(prefix);
|
||
|
}
|
||
|
return ref.current;
|
||
|
}
|
||
|
exports.useId = useId;
|
||
|
});
|
||
|
//# sourceMappingURL=useId.js.map
|