1 | import * as React from 'react';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export default function useDocumentTitle(ref) {
|
7 | let {
|
8 | enabled = true,
|
9 | formatter = (options, route) => {
|
10 | var _options$title;
|
11 |
|
12 | 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;
|
13 | }
|
14 | } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
15 | React.useEffect(() => {
|
16 | if (!enabled) {
|
17 | return;
|
18 | }
|
19 |
|
20 | const navigation = ref.current;
|
21 |
|
22 | if (navigation) {
|
23 | const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute());
|
24 | document.title = title;
|
25 | }
|
26 |
|
27 | return navigation === null || navigation === void 0 ? void 0 : navigation.addListener('options', e => {
|
28 | const title = formatter(e.data.options, navigation === null || navigation === void 0 ? void 0 : navigation.getCurrentRoute());
|
29 | document.title = title;
|
30 | });
|
31 | });
|
32 | }
|
33 |
|
\ | No newline at end of file |