import { useCallback, useEffect, useState } from 'react'; import { readOperatingBranchCode, subscribeOperatingBranch, writeOperatingBranchCode, } from '../utils/operatingBranch'; export function useOperatingBranch() { const [operatingBranchCode, setOperatingBranchCode] = useState(() => readOperatingBranchCode() ); useEffect(() => subscribeOperatingBranch(setOperatingBranchCode), []); const setOperatingBranch = useCallback((code: string | null) => { writeOperatingBranchCode(code); setOperatingBranchCode(code); }, []); return { operatingBranchCode, setOperatingBranch }; }