@limgs/use-title
v1.0.2
Published
React Hook to update your document's title
Downloads
1
Readme
@limNooks/use-title
React Hook to update your document's title
install
npm i @limNooks/use-title
or
yarn add @limNooks/use-title
example
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
const useTitle = initialTitle => {
const [title, setTitle] = useState(initialTitle);
const updateTitle = () => {
const htmlTitle = document.querySelector("title");
htmlTitle.innerText = title;
};
useEffect(updateTitle, [title]);
return setTitle;
};
const App = () => {
const titleUpdater = useTitle("Loading...");
setTimeout(() => titleUpdater("Home"), 5000);
return (
<div className="App">
<div>hi</div>
</div>
);
};
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);