BaseComponent class

The base class for client-side components such as BaseClientSideWebPart or BaseExtension.

Remarks

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the BaseComponent class.

Properties

componentId

Returns the component identifier as defined in the component's associated manifest.

context

Use the context object to access common services and state associated with the component.

instanceId

A unique identifier for the instance of the component.

isDisposed

Returns true if the component has been already disposed.

manifest

Provides access to the manifest for the client-side component. virtual

Methods

dispose()

Disposes the component.

onDispose()

This event method is called at the end of the component's lifecycle. It provides an opportunity to release any associated resources, cancel any outstanding requests, etc. virtual

Property Details

componentId

Returns the component identifier as defined in the component's associated manifest.

get componentId(): string;

Property Value

string

Remarks

Each client-side component has an associated manifest that is used by the sp-loader to load its scripts, and which may include additional metadata about the component. The manifest is uniquely identified using a text string containing a lower case GUID value.

context

Use the context object to access common services and state associated with the component.

protected context?: BaseComponentContext;

Property Value

Remarks

Child classes are expected to override this field by redeclaring it with a specialized type. It is meant to be a read-only property; the type cannot be declared as read-only in the base class (because it is initialized outside the constructor), but child classes should redeclare it as readonly.

instanceId

A unique identifier for the instance of the component.

get instanceId(): string;

Property Value

string

Remarks

A component implementation can be loaded multiple times on the page. For example, if the component is a charting web part, multiple instances of this web part could be added to the SharePoint canvas. The instanceId uniquely identifies each of these instances.

isDisposed

Returns true if the component has been already disposed.

get isDisposed(): boolean;

Property Value

boolean

manifest

Provides access to the manifest for the client-side component. virtual

get manifest(): IClientSideComponentManifest;

Property Value

Remarks

Child classes can override this with more specialized manifest types.

Method Details

dispose()

Disposes the component.

dispose(): void;

Returns

void

Remarks

Third-party code generally does not need to call this method; it's invoked automatically when the lifecycle ends for a web part or extension. To perform custom cleanup when your component is disposed, override the BaseComponent.onDispose() method.

onDispose()

This event method is called at the end of the component's lifecycle. It provides an opportunity to release any associated resources, cancel any outstanding requests, etc. virtual

protected onDispose(): void;

Returns

void