API to render and manipulate extensions of type AsyncPanel. This API works similar to the Panel API. The only difference is the behavior of onAction attribute function.
You should use dynamic imports syntax inside the onAction function to defer loading the panel module. The onAction function must return a Promise instance.
The AsyncPanel extension can be used to defer loading of the panel JavaScript module until the extension is initialized by the product runtime.
1 2type LifecycleCallback = (container: HTMLElement) => void; interface AsyncPanelApi { onMount: (callback: LifecycleCallback) => AsyncPanelApi; onUnmount: (callback: LifecycleCallback) => AsyncPanelApi; }
Provides a container to render custom content in it.
| Name | Type | Description |
|---|---|---|
| container | HTMLElement | HTML element to be used as a container to render custom content. |
Allows to set a cleanup callback to be called when the provided container is about to be deleted.
| Name | Type | Description |
|---|---|---|
| container | HTMLElement | HTML element that was provided to render custom content in it. It's important to unmount any React component you've mounted in there to avoid keeping the component alive when the container is destroyed. |
my-extension.ts1 2import { AsyncPanelExtension } from '@atlassian/clientside-extensions'; import { ExampleContext } from './types'; // Dynamic module loader const panelModuleLoader = () => { return import('./panel-module.ts'); }; /** * @clientside-extension * @extension-point reff.plugins-example-location */ export default AsyncPanelExtension.factory<ExampleContext>((pluginAPI, context) => { return { onAction: panelModuleLoader, }; });
panel-module.ts1 2import { AsyncPanelExtension } from '@atlassian/clientside-extensions'; import { ExampleContext } from './types'; function getPanelContent() { return ` <h4>Cool panel</h4> <p>This is some cool content generated with JS</p> `; } export default function initAsyncPanel( panelApi: AsyncPanelExtension.Api, context: ExampleContext ) { panelApi.onMount(container => { container.innerHTML = getPanelContent(); }); }
types.ts1 2export interface ExampleContext { label: string; }
Rate this page: