Files
openchamber/packages/ui/src/hooks/useRuntimeAPIs.ts
T

19 lines
659 B
TypeScript
Raw Normal View History

2025-12-07 19:32:53 +02:00
import React from 'react';
import type { RuntimeAPISelector, RuntimeAPIs } from '@/lib/api/types';
import { RuntimeAPIContext } from '@/contexts/runtimeAPIContext';
export const useRuntimeAPIs = (): RuntimeAPIs => {
const apis = React.useContext(RuntimeAPIContext);
if (!apis) {
throw new Error('Runtime APIs are not available. Did you forget to wrap the app in <RuntimeAPIProvider>?');
}
return apis;
};
const useRuntimeAPI = <TValue,>(selector: RuntimeAPISelector<TValue>): TValue => {
2025-12-07 19:32:53 +02:00
const apis = useRuntimeAPIs();
return selector(apis);
};
2025-12-13 16:34:17 +02:00
export const useIsVSCodeRuntime = (): boolean => useRuntimeAPI((api) => api.runtime.isVSCode);