diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..80c370f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,45 @@ +"use client"; + +import React, { createContext, useContext, useState, useEffect } from "react"; + +const AccountContext = createContext(); + +export const useAccount = () => { + const context = useContext(AccountContext); + if (!context) { + throw new Error("useAccount must be used within an AccountProvider"); + } + return context; +}; + +export const AccountProvider = ({ children }) => { + const [accountId, setAccountId] = useState(() => { + if (typeof window !== "undefined") { + // Initialize from localStorage if available + return localStorage.getItem("accountId"); + } + return null; + }); + + useEffect(() => { + if (accountId) { + localStorage.setItem("accountId", accountId); + } else { + localStorage.removeItem("accountId"); + } + }, [accountId]); + + + const value = { + accountId, + setAccountId, + }; + + return ( + + {children} + + ); +}; + +export default AccountProvider;