# Lightning Web Component getState Method

Use the `getState` method to retrieve the current state of the rendered Lightning web component for CRM Analytics dashboards.

## Arguments

| Argument Name | Description                                                                                                   |
| ------------- | ------------------------------------------------------------------------------------------------------------- |
| `callback`    | The callback function to handle the `getState` response. See the next section for a basic `callback` example. |

## Example

Add your implementation of the `getState` call into the wrapper Javascript and HTML for your component.

:::note
To use the communityDashboard component, replace `wave-wave-dashboard-lwc` with `wave-community-dashboard`.
:::

The HTML for the component:

```html
<template>
  <lightning-button variant="brand" label="Get Dashboard State" title="Get State Action" onclick={getState} class="slds-m-left_x-small"></lightning-button>
  <wave-wave-dashboard-lwc dashboard="0FK5B000000XiK14AK" height="1000"></wave-wave-dashboard-lwc>
</template>
```

The Javascript for the component, which implements `getState()`:

```javascript
import { LightningElement } from 'lwc';

export default class DashboardWrapper extends LightningElement {
  getState () {
    const dashboard = this.template.querySelector('wave-wave-dashboard-lwc');
    dashboard.getState(function (result, error) {
      if (error) {
        console.warn("getState error: ", error);
      }
      if (result) {
        let state = JSON.parse(JSON.stringify(result.payload));
        console.warn("getState state: ", state);
        let json = JSON.stringify(state, null, 2);
        console.wave("getState as json: ", json);
      }
    });
  }
}
```

In this example, the `callback` function result contains a JSON payload with `state` attributes. Here’s a sample callback result.

```json
{
  "state": {
    "datasets": {},
    "sObjects": {},
    "steps": {
      "Step_1": {
        "values": [],
        "metadata": {
          "groups": ["Field1__c"]
        }
      }
    }
  }
}
```

**See Also**

- [Lightning Web Component `setState` Method](/docs/analytics/dashboard-component/guide/bi-dbcomp-lwc-setstatemethod.md)
