onLayerStateChange

Registers a layerStateChange event handler for a dashboard page, modal, or plugin extension. This allows you to refresh a component's data when it becomes active, or pause resource intensive operations when the component is running in the background.

onLayerStateChange() accepts a callback that's triggered whenever the extension moves from the foreground to the background, or vise versa. For example, this can happen when a Wix user opens or closes a modal.

Signature

Copy

Parameters

NameTypeDescription
callbackFunctionCalled when the layerStateChange event fires. The function receives the extension's new layer state, "foreground" or "background", as an argument.

Returns

Copy

An object containing a function called remove(). Calling this function removes the onLayerStateChange event handler.

Examples

Note: To use this method in self-hosted apps, you need to create a client. See the setup guide for more details.

Refresh data when component comes to the foreground

Note: This example calls dashboard.onBeforeUnload() to display use of the remove() function.

Copy
Did this help?