> ## Documentation Index
> Fetch the complete documentation index at: https://docs-classic.cognigy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# setAppState

## 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

> [accordion] Load an xApp Template
>
> ```js theme={null}
> // 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" })
> ```

> [accordion] Load a Generic HTML xApp page
>
> ```js theme={null}
> // 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 })
> ```

> [accordion] Close an Active xApp Page
>
> ```js theme={null}
> // Close active xApp page
> setAppState(null, {})
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.