> For the complete documentation index, see [llms.txt](https://partner-docs.covergenius.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://partner-docs.covergenius.com/elements/guides/frameworks-and-server-rendering.md).

# Frameworks and Server Rendering

Use CG Elements in a framework and on a server-rendered page.

### Browser only

The SDK renders in the browser. It does not render on the server.

It is safe to import on the server. In Node, Next.js, or Nuxt, the import does not throw. `registerElements()` does nothing without a DOM. `getElement()` returns `undefined`.

Call the SDK from client-only code. Use optional chaining on the result.

```js
getElement()?.render(offerResponse);
```

### Framework examples

{% tabs %}
{% tab title="React" %}
Register and render inside an effect.

```jsx
import { useEffect } from 'react';
import { registerElements, getElement } from '@covergenius/elements';

export function OfferPanel({ offerResponse, onChange }) {
  useEffect(() => {
    registerElements({ environment: 'production' });
    const cgElement = getElement();
    cgElement?.on('change', onChange);
    cgElement?.render(offerResponse);
  }, [offerResponse, onChange]);

  return <cg-elements />;
}
```

Calling `on()` on each render is safe. A new handler replaces the old one.
{% endtab %}

{% tab title="Vue" %}
Register and render in `onMounted`.

```js
import { onMounted } from 'vue';
import { registerElements, getElement } from '@covergenius/elements';

onMounted(() => {
  registerElements({ environment: 'production' });
  getElement()?.render(props.offerResponse);
});
```

Tell Vue that `cg-elements` is a custom element. Add it to the `isCustomElement` option of your compiler.
{% endtab %}
{% endtabs %}

### Next.js and Nuxt

A client component still runs on the server during the first render. Do not call `getElement()!` with a non-null assertion. Put SDK calls in an effect or in `onMounted`.

### Mobile apps

Use a WebView or an installed PWA. The SDK runs in any WebView that supports custom elements.

{% hint style="info" icon="clock" %}
Dedicated bindings for React, Vue, and React Native are planned. Use the SDK directly until they are available.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://partner-docs.covergenius.com/elements/guides/frameworks-and-server-rendering.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
