UNPKG

ahooks-v2

Version:
37 lines (29 loc) 821 B
"use strict"; var __importDefault = this && this.__importDefault || function (mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = require("react"); var useUnmount_1 = __importDefault(require("../useUnmount")); var DEFAULT_OPTIONS = { restoreOnUnmount: false }; function useTitle(title, options) { if (options === void 0) { options = DEFAULT_OPTIONS; } var titleRef = react_1.useRef(document.title); react_1.useEffect(function () { document.title = title; }, [title]); useUnmount_1["default"](function () { if (options && options.restoreOnUnmount) { document.title = titleRef.current; } }); } exports["default"] = typeof document !== 'undefined' ? useTitle : function () {};