Skip to main content

useVersionedContext()

Home > @backstage/version-bridge > useVersionedContext

A hook that simplifies the consumption of a versioned contexts that's stored inside a global singleton.

Signature:

function useVersionedContext<Versions extends {
[version in number]: unknown;
}>(key: string): VersionedValue<Versions> | undefined;

Parameters

Parameter

Type

Description

key

string

A key that uniquely identifies the context.

**Returns:**

VersionedValue<Versions> | undefined

Example

const versionedHolder = useVersionedContext<{ 1: string }>('my-context');

if (!versionedHolder) {
throw new Error('My context is not available!')
}

const myValue = versionedHolder.atVersion(1);

// ...