UNPKG

@ledgerhq/live-common

Version:
28 lines 1.28 kB
import React, { useContext, createContext, useMemo } from "react"; import { useLocalLiveApp } from "../react"; const initialState = []; export const liveAppContext = createContext({ state: initialState, addLocalManifest: () => { }, removeLocalManifestById: () => { }, getLocalLiveAppManifestById: id => id, }); export function LocalLiveAppProvider({ children, db }) { const { state, addLocalManifest, removeLocalManifestById, getLocalLiveAppManifestById } = useLocalLiveApp(db); const value = useMemo(() => ({ state, addLocalManifest, removeLocalManifestById, getLocalLiveAppManifestById, }), [state, addLocalManifest, removeLocalManifestById, getLocalLiveAppManifestById]); // Type assertion: mixed @types/react (18 vs 19) in deps make Provider's children type incompatible with our ReactNode. return (React.createElement(liveAppContext.Provider, { value: value }, children)); } export function useLocalLiveAppManifest(appId) { const getLocalLiveAppManifestById = useContext(liveAppContext).getLocalLiveAppManifestById; return appId ? getLocalLiveAppManifestById(appId) : undefined; } export function useLocalLiveAppContext() { return useContext(liveAppContext); } //# sourceMappingURL=index.js.map