In This Article
observeState
Allows to receive contextual state and environmental information of the dashboard.
The callback function provided to observeState
receives the state data. The function is triggered when dashboard component initializes and whenever the state data is updated.
Common use cases for this method
- A dashboard page in an app's backoffice, receiving environment data from the host such as the user's locale.
- A widget rendered within the dashboard, receiving contextual data from the page that's hosting it.
- A modal opened from a dashboard page or from a widget, receiving data from either.
Signature
Copy
1observeState<P>(observer: Observer<P>): void
Function Parameters
Name | Type | Description |
---|---|---|
observer | Observer | Callback function for receiving state data that takes two parameters:componentParams : The data that is sent to your component by your host, who is responsible for rendering it.environmentState : General information about the user's present environment. |
Observer
Copy
1(componentParams: P, environmentState: EnvironmentState) => void
Name | Type | Description |
---|---|---|
componentParams | P | A generic type parameter that indicates the data that is sent to your component by your host, who is responsible for rendering the component. |
environmentState | EnvironmentState | State of the dashboard's environment. |
EnvironmentState
Copy
1{2 locale: string;3 pageLocation: PageLocation;4}
Name | Type | Description |
---|---|---|
locale | string | User's locale in ISO 639-1 format. |
pageLocation | PageLocation | Information about the currently rendered page location. |
PageLocation
Copy
1{2 pageId: string;3 pathname: string;4 search?: string;5 hash?: string;6}
Name | Type | Description |
---|---|---|
pageId | string | ID of the current page. |
pathname | string | Any parts of the current URL path appended to the page's full URL path. Learn more. |
search | string | Optional. The current URL's query string. |
hash | string | Optional. The current URL's fragment identifier. |
About pathname
The value of pathname
is any part of the URL path that comes after the route to the current dashboard page.
For third-party app dashboard pages, this is anything appended to the URL after the Relative route value that you set when creating the dashboard page extension in the Wix Developers Center.
Examples
To set up a dashboard client, refer to the setup guide.
Receive state passed by your host
Copy
1client.dashboard.observeState((componentParams) => {2 // This value is logged on initialization and whenever the `observer` object changes. 3 console.log(componentParams.customPageParameter);4});
Receive user's locale
Copy
1client.dashboard.observeState((_, environmentState) => {2 // This value is logged on initialization and whenever the `observer` object changes. 3 console.log(environmentState.locale); 4});
Was this helpful?
Yes
No