import { useEffect, useState } from "react"; import { HelmetProvider, Helmet } from "react-helmet-async"; import { apiGet } from "../../lib/api"; let cachedStoreName: string | null = null; let storeNamePromise: Promise | null = null; async function getStoreName(): Promise { if (cachedStoreName !== null) return cachedStoreName; if (!storeNamePromise) { storeNamePromise = apiGet<{ data: { toko?: { nama?: string } } }>( "/admin-api/pengaturan" ) .then((res) => { const name = res?.data?.toko?.nama?.trim(); cachedStoreName = name ? name : null; return cachedStoreName; }) .catch(() => { cachedStoreName = null; return null; }) .finally(() => { storeNamePromise = null; }); } return storeNamePromise; } const PageMeta = ({ title, description, }: { title: string; description: string; }) => { const [storeName, setStoreName] = useState(cachedStoreName); useEffect(() => { let mounted = true; if (cachedStoreName !== null) return; getStoreName().then((name) => { if (mounted) setStoreName(name); }); return () => { mounted = false; }; }, []); const fullTitle = storeName ? `${storeName} - ${title}` : title; return ( {fullTitle} ); }; export const AppWrapper = ({ children }: { children: React.ReactNode }) => ( {children} ); export default PageMeta;