import type { ReactNode } from 'react'; import { createContext, useContext, useMemo } from 'react'; import { Roc } from 'rest-on-couch-client'; const rocContext = createContext(null); export function useRoc() { const roc = useContext(rocContext) as Roc; if (!roc) { throw new Error('missing roc'); } return roc; } export function RocProvider(props: { children: ReactNode; url: string; database: string; }) { const { url, database, children } = props; const roc = useMemo(() => new Roc({ url, database }), [url, database]); return {children}; }