From 31d6352ab8855754ef18c01763d3c1b5a68de857 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 22 Dec 2022 15:29:18 +0700 Subject: Appbar component and auth hook (useAuth) --- src/components/Header.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/components/Header.js') diff --git a/src/components/Header.js b/src/components/Header.js index a294c140..d41847ef 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -11,7 +11,7 @@ import { } from "@heroicons/react/24/outline"; // Helpers -import { getAuth } from "../helpers/auth"; +import { getAuth, useAuth } from "../helpers/auth"; // Components import Link from "./Link"; // Images @@ -24,11 +24,7 @@ export default function Header({ title }) { const [suggestions, setSuggestions] = useState([]); const searchQueryRef = useRef(); const [isMenuActive, setIsMenuActive] = useState(false); - const [auth, setAuth] = useState(); - - useEffect(() => { - if (!auth) setAuth(getAuth()); - }, [auth]); + const [auth, setAuth] = useAuth(); useEffect(() => { if (q) { @@ -76,24 +72,23 @@ export default function Header({ title }) {
- {auth ? ( -

Hi, {auth.name}

- ) : ( + { auth && ( + +

Hi, {auth.name}

+
+ +
+ + ) } + + { !auth && ( <> Masuk Daftar - )} + ) }
- {auth && ( - - Profil Saya -
- -
- - )} Semua Brand
-- cgit v1.2.3