import React, { useState, useEffect } from "react";
/**
 * Sets document title to the given string.
 *
 * The operating is ignored if a title has already been  (e.g. with `<title>` tag or a call to document.title)
 * unless the `force` flag is set to to true.
 *
 * @param title The title string to use
 * @param force Sets the document title even if it is already set
 */
export const useTitle = (title, force = false) => {
    var _a, _b;
    const [originalTitle] = useState((_b = (_a = document.getElementsByTagName("title")) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null);
    // Document title can be set by a prop, but will not override an original <title> tag
    // Defaults to "Toolbar"
    useEffect(() => {
        if (!originalTitle || force) {
            document.title = title;
        }
    }, [title]);
};
/**
 * Adapter for using useTitle() hook in class based React components
 */
export const Title = ({ title }) => {
    useTitle(title);
    return React.createElement(React.Fragment, null);
};
//# sourceMappingURL=useTitle.js.map