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