diff options
-rw-r--r-- | thallium-frontend/src/components/CartStatus.tsx | 10 | ||||
-rw-r--r-- | thallium-frontend/src/utils/hooks.ts | 14 |
2 files changed, 12 insertions, 12 deletions
diff --git a/thallium-frontend/src/components/CartStatus.tsx b/thallium-frontend/src/components/CartStatus.tsx index 848e1cc..5b6d1e8 100644 --- a/thallium-frontend/src/components/CartStatus.tsx +++ b/thallium-frontend/src/components/CartStatus.tsx @@ -21,7 +21,7 @@ margin-bottom: 30px; right: 0; margin-right: 30px; transition: all 0.25s; -` +`; const CartStatus = () => { const cart = useSelector((state: RootState) => state.cart); @@ -32,16 +32,16 @@ const CartStatus = () => { const buttonVisible = useVisible(staticButtonRef); useEffect(() => { - console.log(buttonVisible) - }, [buttonVisible]) + console.log(buttonVisible); + }, [buttonVisible]); - const checkoutMsg = total > 0 ? "Checkout >" : "Add some items to proceed to checkout" + const checkoutMsg = total > 0 ? "Checkout >" : "Add some items to proceed to checkout"; const navigate = useNavigate(); const buttonCallback = () => { navigate("/checkout"); - } + }; return <> <StatusHolder>You currently have {total} item{total !== 1 ? "s" : null} in your cart, totalling ${price.toFixed(2)} USD</StatusHolder> diff --git a/thallium-frontend/src/utils/hooks.ts b/thallium-frontend/src/utils/hooks.ts index 997f274..337ccf2 100644 --- a/thallium-frontend/src/utils/hooks.ts +++ b/thallium-frontend/src/utils/hooks.ts @@ -2,16 +2,16 @@ import { useState, useEffect } from "react"; import { type RefObject } from "react"; export function useVisible(ref: RefObject<HTMLElement>) { - const [isVisible, setVisible] = useState(false) + const [isVisible, setVisible] = useState(false); useEffect(() => { const observer = new IntersectionObserver( - ([entry]) => setVisible(entry.isIntersecting) - ) + ([entry]) => { setVisible(entry.isIntersecting); } + ); if (ref.current) - observer.observe(ref.current) - return () => observer.disconnect() - }, []) + observer.observe(ref.current); + return () => { observer.disconnect(); }; + }, [ref]); - return isVisible + return isVisible; } |