## Syntax

`setAppState(xAppTemplateId, xAppTemplateData)`

## Description

Updates the state of the xApp Session for the current conversation. Only works if an xApp Session was started beforehand.**Parameters:**

- `xAppTemplateId`: `string` — the URL to a hosted xApp template, `generic-html`, or `null`.  
  
  - If a URL is provided, the xApp template is loaded from that URL.  
  - If `generic-html` is provided, the xApp page SDK is loaded from the host, and the HTML code defined in `xAppTemplateData.html` is displayed.  
  - If `null` is provided, the active xApp page is closed.

- `xAppTemplateData`: `Record<string, unknown>` — the data payload for the xApp page.

**Returns:**`void`

## Examples

Load an xApp Template

```javascript
// Load an xApp Template
// loads the xApp template hosted at `https://my-xapp-template-url` as an xApp page
// - injects `{ my: "xapp-template-data" }` to the xApp
// - waits for the xApp page to load, then displays it to the end user
setAppState("https://my-xapp-template-url", { my: "xapp-template-data" })
```

Load a Generic HTML xApp page

```javascript
// Load generic HTML
/* javascript
const html = `
<html>
  <body>
    Hello, World!
    <button type="button" onclick="SDK.submit({});">continue</button>
    <script src="/sdk/app-page-sdk.js"></script>
  </body>
</html>
`;
// loads the HTML code defined in `html` as an xApp page.
// loads the xApp page SDK from its host
setAppState("generic-html", { html })
```

Close an Active xApp Page

```javascript
// Close active xApp page
setAppState(null, {})
```
