import { useState, createContext, useContext, ReactNode } from 'react'; interface InstanceContextValue { currentInstance: string | null; setCurrentInstance: (name: string | null) => void; } const InstanceContext = createContext(undefined); export function InstanceProvider({ children }: { children: ReactNode }) { const [currentInstance, setCurrentInstanceState] = useState( () => localStorage.getItem('currentInstance') ); const setCurrentInstance = (name: string | null) => { setCurrentInstanceState(name); if (name) { localStorage.setItem('currentInstance', name); } else { localStorage.removeItem('currentInstance'); } }; return ( {children} ); } export function useInstanceContext() { const context = useContext(InstanceContext); if (context === undefined) { throw new Error('useInstanceContext must be used within an InstanceProvider'); } return context; }