diff --git a/packages/core-app-api/src/apis/system/ApiProvider.tsx b/packages/core-app-api/src/apis/system/ApiProvider.tsx index bffb9986c7..aa57fa9310 100644 --- a/packages/core-app-api/src/apis/system/ApiProvider.tsx +++ b/packages/core-app-api/src/apis/system/ApiProvider.tsx @@ -14,19 +14,13 @@ * limitations under the License. */ -import React, { - createContext, - useContext, - ReactNode, - PropsWithChildren, -} from 'react'; +import React, { useContext, ReactNode, PropsWithChildren } from 'react'; import PropTypes from 'prop-types'; import { ApiHolder } from '@backstage/core-plugin-api'; import { ApiAggregator } from './ApiAggregator'; import { - VersionedValue, createVersionedValueMap, - getOrCreateGlobalSingleton, + createVersionedContext, } from '@backstage/version-bridge'; type ApiProviderProps = { @@ -34,10 +28,7 @@ type ApiProviderProps = { children: ReactNode; }; -type ApiContextType = VersionedValue<{ 1: ApiHolder }> | undefined; -const ApiContext = getOrCreateGlobalSingleton('api-context', () => - createContext(undefined), -); +const ApiContext = createVersionedContext<{ 1: ApiHolder }>('api-context'); export const ApiProvider = ({ apis, diff --git a/packages/core-app-api/src/app/AppContext.tsx b/packages/core-app-api/src/app/AppContext.tsx index 640d814da0..f39d9a095e 100644 --- a/packages/core-app-api/src/app/AppContext.tsx +++ b/packages/core-app-api/src/app/AppContext.tsx @@ -14,18 +14,14 @@ * limitations under the License. */ -import React, { createContext, PropsWithChildren } from 'react'; +import React, { PropsWithChildren } from 'react'; import { - VersionedValue, createVersionedValueMap, - getOrCreateGlobalSingleton, + createVersionedContext, } from '@backstage/version-bridge'; import { AppContext as AppContextV1 } from './types'; -type AppContextType = VersionedValue<{ 1: AppContextV1 }> | undefined; -const AppContext = getOrCreateGlobalSingleton('app-context', () => - createContext(undefined), -); +const AppContext = createVersionedContext<{ 1: AppContextV1 }>('app-context'); type Props = { appContext: AppContextV1; diff --git a/packages/core-app-api/src/routing/RoutingProvider.tsx b/packages/core-app-api/src/routing/RoutingProvider.tsx index b2aaf3df3b..2ab1686368 100644 --- a/packages/core-app-api/src/routing/RoutingProvider.tsx +++ b/packages/core-app-api/src/routing/RoutingProvider.tsx @@ -14,24 +14,21 @@ * limitations under the License. */ -import React, { createContext, ReactNode } from 'react'; +import React, { ReactNode } from 'react'; import { ExternalRouteRef, RouteRef, SubRouteRef, } from '@backstage/core-plugin-api'; import { - VersionedValue, createVersionedValueMap, - getOrCreateGlobalSingleton, + createVersionedContext, } from '@backstage/version-bridge'; import { RouteResolver } from './RouteResolver'; import { BackstageRouteObject } from './types'; -type RoutingContextType = VersionedValue<{ 1: RouteResolver }> | undefined; -const RoutingContext = getOrCreateGlobalSingleton('routing-context', () => - createContext(undefined), -); +const RoutingContext = + createVersionedContext<{ 1: RouteResolver }>('routing-context'); type ProviderProps = { routePaths: Map;