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 vice versa. For example, this can happen when a Wix user opens or closes a modal.
| Name | Type | Description |
|---|---|---|
callback | Function | Called when the layerStateChange event fires. The function receives the extension's new layer state, "foreground" or "background", as an argument. |
An object containing a method called remove(). Calling this method removes the onLayerStateChange event handler.
Note: To call this method in self-hosted apps, you need to create a client. See the setup guide for more details.
Note: This example calls dashboard.onBeforeUnload() to demonstrate use of the remove() function.