Search.../

observeState( )

Defines a callback function that receives changes to the state of a dashboard page's environment.

Description

This function can only be used in page code files for dashboard pages created in the Wix Editor or with Wix Blocks.

Use the data passed to observeState()'s callback function to dynamically update a dashboard page's content.

The callback function passed to observeState() is triggered when the dashboard page is initialized and every time it's updated.

Syntax

function observeState(observer: observeStateCallback): void
observer: function observeStateCallback(pageParams: Object, environmentState: EnvironmentState): void

observeState Parameters

NAME
TYPE
DESCRIPTION
observer

Callback function for receiving state data.

Returns

This function does not return anything.

Return Type:

void

observeStateCallback Parameters

NAME
TYPE
DESCRIPTION
pageParams
Object

Custom parameters passed to the dashboard page.

environmentState
EnvironmentState

Data about the dashboard's environment.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Receive state data and log it to the console

Copy Code
1import { observeState } from 'wix-dashboard';
2
3// ...
4
5observeState((pageParams, environmentState) => {
6 console.log('custom param', pageParams.customParam);
7 console.log('locale', environmentState.locale);
8});