UNPKG

2.27 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = useDocumentTitle;
7
8var React = _interopRequireWildcard(require("react"));
9
10function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
12function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
14/**
15 * Set the document title for the active screen
16 */
17function useDocumentTitle(ref, {
18 enabled = true,
19 formatter = (options, route) => {
20 var _options$title;
21
22 return (_options$title = options === null || options === void 0 ? void 0 : options.title) !== null && _options$title !== void 0 ? _options$title : route === null || route === void 0 ? void 0 : route.name;
23 }
24} = {}) {
25 React.useEffect(() => {
26 if (!enabled) {
27 return;
28 }
29
30 const navigation = ref.current;
31
32 if (navigation) {
33 const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute());
34 document.title = title;
35 }
36
37 return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', e => {
38 const title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute());
39 document.title = title;
40 });
41 });
42}
43//# sourceMappingURL=useDocumentTitle.js.map
\No newline at end of file