Set custom page title

This commit is contained in:
Florian Scholdei
2019-12-12 16:25:33 +01:00
parent 5906f3a03b
commit 90c78cfeba

View File

@@ -1,17 +1,30 @@
import React from "react"; import React, { FC, useEffect } from "react";
type Props = { type Props = {
title?: string; title?: string;
customPageTitle?: string;
preventRefreshingPageTitle?: boolean;
}; };
class Title extends React.Component<Props> { const Title: FC<Props> = ({ title, preventRefreshingPageTitle, customPageTitle }) => {
render() { useEffect(() => {
const { title } = this.props; if (!preventRefreshingPageTitle) {
if (customPageTitle) {
document.title = customPageTitle;
} else if (title) {
document.title = title;
}
}
});
if (title) { if (title) {
return <h1 className="title">{title}</h1>; return <h1 className="title">{title}</h1>;
} }
return null; return null;
} };
}
Title.defaultProps = {
preventRefreshingPageTitle: false
};
export default Title; export default Title;