import { sleep } from "~/helpers"; const currentTenant = localStorage.getItem("tenants-current"); const setCurrentTenant = (tenantId: string) => localStorage.setItem("tenants-current", tenantId); async function getCurrentTenantAsync() { let currentTenant = localStorage.getItem("tenants-current"); let attempts = 0; do { attempts++; await sleep(200); currentTenant = localStorage.getItem("tenants-current"); } while (!currentTenant && attempts < 5); return currentTenant; } export const useCurrentTenant = () => { return { currentTenant, setCurrentTenant, getCurrentTenantAsync }; }