Skip to content

Commit

Permalink
Finish feature/118
Browse files Browse the repository at this point in the history
  • Loading branch information
dlcastillop authored Oct 27, 2024
2 parents dcc5651 + 0a0a91c commit 2bf04ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
11 changes: 5 additions & 6 deletions src/hooks/js/useTitle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useState, useEffect } from 'react';
import { useState } from 'react';

export const useTitle = () => {
const [title, setTitle] = useState(document.title);

useEffect(() => {
document.title = title;
}, [title]);

const changeTitle = (newTitle) => setTitle(newTitle);
const changeTitle = (newTitle) => {
document.title = newTitle;
setTitle(newTitle);
}

return { title, changeTitle };
};
18 changes: 6 additions & 12 deletions src/hooks/ts/useTitle.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { useState, useEffect } from 'react';
import { useState } from 'react';

interface UseTitleOutput {
title: string;
changeTitle: (newTitle: string) => void;
}

export const useTitle = (): UseTitleOutput => {
export const useTitle = () => {
const [title, setTitle] = useState<string>(document.title);

useEffect(() => {
document.title = title;
}, [title]);

const changeTitle = (newTitle: string) => setTitle(newTitle);
const changeTitle = (newTitle: string) => {
document.title = newTitle;
setTitle(newTitle);
}

return { title, changeTitle };
};

0 comments on commit 2bf04ff

Please sign in to comment.