MCPcopy Create free account
hub / github.com/microsoft/SandDance / useTarget

Function useTarget

docs/app/js/sanddance-app.js:34881–34909  ·  view source on GitHub ↗
(target, hostElement)

Source from the content-addressed store, hash-verified

34879var _react = require("react");
34880var _reactWindowProvider = require("@fluentui/react-window-provider");
34881function useTarget(target, hostElement) {
34882 var _a;
34883 var previousTargetProp = _react.useRef();
34884 var targetRef = _react.useRef(null);
34885 /**
34886 * Stores an instance of Window, used to check
34887 * for server side rendering and if focus was lost.
34888 */ var targetWindow = (0, _reactWindowProvider.useWindow)();
34889 // If the target element changed, find the new one. If we are tracking
34890 // target with class name, always find element because we do not know if
34891 // fabric has rendered a new element and disposed the old element.
34892 if (!target || target !== previousTargetProp.current || typeof target === "string") {
34893 var currentElement = (_a = hostElement) === null || _a === void 0 ? void 0 : _a.current;
34894 if (target) {
34895 if (typeof target === "string") {
34896 var currentDoc = (0, _utilities.getDocument)(currentElement);
34897 targetRef.current = currentDoc ? currentDoc.querySelector(target) : null;
34898 } else if ("stopPropagation" in target) targetRef.current = target;
34899 else if ("getBoundingClientRect" in target) targetRef.current = target;
34900 else if ("current" in target) targetRef.current = target.current;
34901 else targetRef.current = target;
34902 }
34903 previousTargetProp.current = target;
34904 }
34905 return [
34906 targetRef,
34907 targetWindow
34908 ];
34909}
34910
34911},{"@uifabric/utilities":"uTCgd","react":"8ePka","@fluentui/react-window-provider":"5Gutx","@parcel/transformer-js/src/esmodule-helpers.js":"jA2du"}],"9U2u9":[function(require,module,exports) {
34912var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected