]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/pages/User.js
add helmet
[alttp.git] / resources / js / components / pages / User.js
index bb26bfae902e24fffec8501e6e6f1a34216b9546..b481112456813a4613a572702bd9b460880969c1 100644 (file)
@@ -1,5 +1,6 @@
 import axios from 'axios';
 import React, { useEffect, useState } from 'react';
+import { Helmet } from 'react-helmet';
 import { useParams } from 'react-router-dom';
 
 import ErrorBoundary from '../common/ErrorBoundary';
@@ -18,19 +19,22 @@ const User = () => {
 
        useEffect(() => {
                setLoading(true);
+               const ctrl = new AbortController();
                axios
-                       .get(`/api/users/${id}`)
+                       .get(`/api/users/${id}`, { signal: ctrl.signal })
                        .then(response => {
                                setError(null);
                                setLoading(false);
                                setUser(response.data);
-                               window.document.title = response.data.nickname || response.data.username;
                        })
                        .catch(error => {
                                setError(error);
                                setLoading(false);
                                setUser(null);
                        });
+               return () => {
+                       ctrl.abort();
+               };
        }, [id]);
 
        useEffect(() => {
@@ -60,6 +64,9 @@ const User = () => {
        }
 
        return <ErrorBoundary>
+               <Helmet>
+                       <title>{user.nickname || user.username}</title>
+               </Helmet>
                <Profile user={user} />
        </ErrorBoundary>;
 };