Skip to content

React Hooks API Reference ​

All exports from @pandino/react-hooks.

ts
import { PandinoProvider, useService, useServiceTracker, useRegisterService } from '@pandino/react-hooks';

Hooks ​

HookReturn TypeDescription
useService{ service, loading, error }Looks up a single service
useServiceTracker{ services, loading, error }Tracks all matching services dynamically
useRegisterService{ registration, isRegistered, error, updateProperties }Registers a service from a component
useBundle{ bundle, loading, error }Looks up a bundle by ID or symbolic name
useAllBundles{ bundles, loading, error }Returns all installed bundles
useBundleContextBundleContext | nullReturns the current bundle context
usePandinoContextPandinoContextTypeReturns the full Pandino context

useService ​

Looks up a single service by class name or function, with optional LDAP filter.

ts
const { service, loading, error } = useService<MyService>('MyService');
const { service } = useService<MyService>('MyService', '(version>=2.0)');
ParameterTypeDescription
serviceClassstring | FunctionService interface name or constructor
filter?stringOptional LDAP filter
Return PropertyTypeDescription
serviceT | nullThe service instance, or null if not found
loadingbooleantrue while the framework is initializing
errorError | nullError if lookup failed

useServiceTracker ​

Tracks all matching services and re-renders when services are added, modified, or removed.

ts
const { services, loading, error } = useServiceTracker<MyPlugin>('MyPlugin');
const { services } = useServiceTracker<MyPlugin>('MyPlugin', '(vendor=Example)');
ParameterTypeDescription
serviceClassstringService interface name
filter?stringOptional LDAP filter (combined with objectClass automatically)
Return PropertyTypeDescription
servicesT[]Array of tracked service instances
loadingbooleantrue while the framework is initializing
errorError | nullError if tracking failed

useRegisterService ​

Registers a service and automatically unregisters on unmount.

ts
const myImpl = useMemo(() => ({ greet: () => 'Hello' }), []);
const { isRegistered, updateProperties } = useRegisterService('GreeterService', myImpl, { version: '1.0' });
ParameterTypeDescription
serviceClassstring | string[] | FunctionInterface(s) to register under
serviceImplTThe service implementation object
properties?Record<string, any>Optional service properties
Return PropertyTypeDescription
registrationServiceRegistration<T> | nullThe registration handle
isRegisteredbooleantrue after successful registration
errorError | nullError if registration failed
updateProperties(newProperties: Record<string, any>) => voidUpdates the service properties

useBundle ​

Looks up a bundle by numeric ID or symbolic name.

ts
const { bundle, loading, error } = useBundle('com.example.my-bundle');
const { bundle } = useBundle(3);
ParameterTypeDescription
bundleIdOrNamenumber | stringBundle ID or symbolic name
Return PropertyTypeDescription
bundleBundle | nullThe bundle, or null if not found
loadingbooleantrue while the framework is initializing
errorError | nullError if lookup failed

useAllBundles ​

Returns all installed bundles.

ts
const { bundles, loading, error } = useAllBundles();
Return PropertyTypeDescription
bundlesBundle[]All installed bundles
loadingbooleantrue while the framework is initializing
errorError | nullError if lookup failed

useBundleContext ​

Returns the BundleContext from the nearest PandinoProvider.

ts
const context = useBundleContext();
if (context) {
  const ref = context.getServiceReference('MyService');
}

Returns: BundleContext | null

usePandinoContext ​

Returns the full Pandino context including framework, bundle context, and initialization state.

ts
const { framework, bundleContext, isInitialized, error } = usePandinoContext();

Returns: PandinoContextType (see Types below)

Components ​

ComponentDescription
<PandinoProvider>Initializes the framework and provides context to children
<BundleInfo>Displays bundle information via render prop
<ServiceConsumer>Consumes a service via render prop
<ComponentProxy>Renders a service as a React component

PandinoProvider ​

Initializes the Pandino framework and provides it to the component tree.

tsx
<PandinoProvider
  bootstrapConfig={{ frameworkLogLevel: LogLevel.DEBUG }}
  bundles={[import('./my-bundle')]}
>
  <App />
</PandinoProvider>
PropTypeDefaultDescription
childrenReactNode-Child components
bootstrapConfig?BootstrapConfig{}Framework configuration
bundles?Array<Promise<BundleModule>>[]Bundle modules to install and start on init

BundleInfo ​

Provides bundle information through a render prop. Without a render prop, renders a default info table.

tsx
<BundleInfo bundleIdOrName="com.example.my-bundle">
  {({ bundle, loading, error, stateToString }) => (
    <span>{bundle ? stateToString(bundle.getState()) : 'N/A'}</span>
  )}
</BundleInfo>
PropTypeDescription
bundleIdOrNamenumber | stringBundle ID or symbolic name
children?(props: { bundle, loading, error, stateToString }) => ReactNodeRender prop. If omitted, renders a default info table

ServiceConsumer ​

Consumes a service via render prop pattern.

tsx
<ServiceConsumer<MyService> serviceClass="MyService" filter="(version>=2.0)">
  {({ service, loading, error }) => (
    service ? <div>{service.getData()}</div> : <div>Loading...</div>
  )}
</ServiceConsumer>
PropTypeDescription
serviceClassstring | FunctionService interface name or constructor
filter?stringOptional LDAP filter
children(props: { service: T | null, loading: boolean, error: Error | null }) => ReactNodeRender prop

ComponentProxy ​

Renders a service as a React component. Falls back to children while loading or on error.

tsx
<ComponentProxy serviceClass="WidgetComponent" filter="(type=header)">
  <FallbackWidget />
</ComponentProxy>
PropTypeDescription
serviceClassstring | FunctionService interface to look up
filterstringLDAP filter to match the service
children?ReactNodeFallback content shown while loading or on error
...restPropsanyAdditional props passed to the rendered service component

Types ​

PandinoContextType ​

PropertyTypeDescription
frameworkOSGiFramework | nullThe framework instance
bundleContextBundleContext | nullThe system bundle context
isInitializedbooleantrue once the framework and all initial bundles are started
errorError | nullInitialization error, if any

bundleStateToString ​

Utility function that converts a numeric bundle state to a human-readable string.

ts
import { bundleStateToString } from '@pandino/react-hooks';

bundleStateToString(32); // 'ACTIVE'
bundleStateToString(1);  // 'UNINSTALLED'
ParameterTypeDescription
statenumberNumeric bundle state (from BUNDLE_STATES)

Returns: string -- One of 'INSTALLED', 'RESOLVED', 'STARTING', 'ACTIVE', 'STOPPING', 'UNINSTALLED', or 'UNKNOWN (n)'.

Released under the Eclipse Public License 2.0.