Create custom hook to change document title
This commit is contained in:
parent
df60338352
commit
cf04dd22d4
6 changed files with 23 additions and 0 deletions
11
src/hooks/useDocumentTitle.js
Normal file
11
src/hooks/useDocumentTitle.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
const useDocumentTitle = title => {
|
||||||
|
const [documentTitle] = useState(title);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
document.title = documentTitle;
|
||||||
|
}, [documentTitle]);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { useDocumentTitle };
|
|
@ -1,4 +1,7 @@
|
||||||
|
import { useDocumentTitle } from '../../hooks/useDocumentTitle';
|
||||||
|
|
||||||
function Calendar() {
|
function Calendar() {
|
||||||
|
useDocumentTitle('Calendário');
|
||||||
return <h1>Calendário Acadêmico</h1>;
|
return <h1>Calendário Acadêmico</h1>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useUser } from '../../context/user';
|
import { useUser } from '../../context/user';
|
||||||
|
import { useDocumentTitle } from '../../hooks/useDocumentTitle';
|
||||||
import useLayoutType from '../../hooks/useLayoutType';
|
import useLayoutType from '../../hooks/useLayoutType';
|
||||||
import View from './View';
|
import View from './View';
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
|
useDocumentTitle('Página Inicial');
|
||||||
const layoutType = useLayoutType();
|
const layoutType = useLayoutType();
|
||||||
const { fetchClassrooms, fetchAssignments } = useUser();
|
const { fetchClassrooms, fetchAssignments } = useUser();
|
||||||
const [classrooms, setClassrooms] = useState(null);
|
const [classrooms, setClassrooms] = useState(null);
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
import { useDocumentTitle } from '../../hooks/useDocumentTitle';
|
||||||
|
|
||||||
function Information() {
|
function Information() {
|
||||||
|
useDocumentTitle('Informações');
|
||||||
return <h1>Informações</h1>;
|
return <h1>Informações</h1>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useAuthState } from '../../context/auth';
|
import { useAuthState } from '../../context/auth';
|
||||||
|
import { useDocumentTitle } from '../../hooks/useDocumentTitle';
|
||||||
import useLayoutType from '../../hooks/useLayoutType';
|
import useLayoutType from '../../hooks/useLayoutType';
|
||||||
|
|
||||||
import View from './View';
|
import View from './View';
|
||||||
|
|
||||||
function Login() {
|
function Login() {
|
||||||
|
useDocumentTitle('Entrar');
|
||||||
const { login, isPending, isError, error } = useAuthState();
|
const { login, isPending, isError, error } = useAuthState();
|
||||||
const layoutType = useLayoutType();
|
const layoutType = useLayoutType();
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { Link } from '@mui/material';
|
import { Link } from '@mui/material';
|
||||||
import { Container } from '@mui/system';
|
import { Container } from '@mui/system';
|
||||||
|
import { useDocumentTitle } from '../../hooks/useDocumentTitle';
|
||||||
|
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
|
|
||||||
function UnauthenticatedHome() {
|
function UnauthenticatedHome() {
|
||||||
|
useDocumentTitle('Seja bem-vindo');
|
||||||
const { container } = styles.desktop;
|
const { container } = styles.desktop;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue