> For the complete documentation index, see [llms.txt](https://docs.formsort.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.formsort.com/publishing-and-deployment/embedding/web-embed-api/react-embed.md).

# React-embed

Embed Formsort flows within react components.

This is a handy wrapper around [@formsort/web-embed-api](https://github.com/formsort/oss/blob/master/packages/web-embed-api).

{% hint style="info" %}
Once you are finished writing your React-embed code, check out our [Setting up a dev environment](/publishing-and-deployment/embedding/setting-up-a-dev-environment.md) doc to begin testing the embed in your webpage.
{% endhint %}

## Installation

Add `@formsort/react-embed` to your project by executing `yarn add @formsort/react-embed` or `npm install @formsort/react-embed`.

## Usage

Here's an example of basic usage:

```jsx
import React from 'react';
import EmbedFlow from '@formsort/react-embed';

const EmbedFlowExample: React.FunctionComponent = () => (
  <div>
    <EmbedFlow
      clientLabel="formsort"
      flowLabel="onboarding"
      variantLabel="main"
      embedConfig={{
        style: {
          width: '100%',
          height: '100%',
        },
      }}
      // Event listener examples
      onFlowLoaded={() => {console.log("Flow has loaded!")}}
      onStepCompleted={(answers) => console.log(answers)}
      onFlowFinalized={(answers) => console.log(answers)}
    />
  </div>
);
```

#### Events

You can add event listeners to flows like `Flowloaded`, `redirect` etc. See [all event listeners](https://github.com/formsort/oss/tree/master/packages/web-embed-api#event-listeners).

#### Props

<table><thead><tr><th width="185">Prop name</th><th width="221">Description</th><th width="77">Req'd</th><th width="287">Example values</th></tr></thead><tbody><tr><td>clientLabel</td><td>client name</td><td>yes</td><td><code>formsort</code></td></tr><tr><td>flowLabel</td><td>flow name</td><td>yes</td><td><code>onboarding</code></td></tr><tr><td>variantLabel</td><td>variant name</td><td>no</td><td><code>main</code></td></tr><tr><td>responderUuid</td><td>responder uuid to load existing answers for</td><td>no</td><td><code>e4923baa-dc2d-4555-813c-a166952292fa</code></td></tr><tr><td>formsortEnv</td><td>formsort integrations environment label, if not using production</td><td>no</td><td><code>staging</code></td></tr><tr><td>queryParams</td><td>additional query params, to pre-populate answers in the form</td><td>no</td><td><code>[['name', 'Olivia'], ['age', '3']]</code></td></tr><tr><td>embedConfig</td><td>config passed to the underlying<br><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api"><code>formsortWebEmbed</code></a></td><td>no</td><td><code>{ style: { height: '100%' } }</code></td></tr><tr><td>onFlowLoaded</td><td><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api#flowloaded-answers--key-string-any----void">event listener</a></td><td>no</td><td><code>() => { console.log('flow loaded') }</code></td></tr><tr><td>onFlowClosed</td><td><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api#flowclosed-answers--key-string-any---void">event listener</a></td><td>no</td><td><code>() => { console.log('flow closed') }</code></td></tr><tr><td>onFlowFinalized</td><td><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api#flowfinalized-answers--key-string-any---void">event listener</a></td><td>no</td><td><code>() => { console.log('flow finalized') }</code></td></tr><tr><td>onStepLoaded</td><td><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api#steploaded-answers--key-string-any---void">event listener</a></td><td>no</td><td><code>() => { console.log('step loaded') }</code></td></tr><tr><td>onStepCompleted</td><td><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api#steploaded-answers--key-string-any---void">event listener</a></td><td>no</td><td><code>() => { console.log('step loaded') }</code></td></tr><tr><td>onRedirect</td><td><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api#redirect--url-string-answers--key-string-any-----cancel-boolean---undefined">event listener</a></td><td>no</td><td><code>(url: string) => { console.log('redirecting to:', url) }</code></td></tr><tr><td>onUnauthorized</td><td><a href="https://github.com/formsort/oss/tree/master/packages/web-embed-api#unauthorized---void">event listener</a></td><td>no</td><td><code>() => { console.log('ID token is missing or invalid.') }</code></td></tr></tbody></table>

## Loading a specific variant revision

You can use query parameters to load a specific variant revision. Do not use this if you want to show the latest variant.

```jsx
import React from 'react';
import EmbedFlow from '@formsort/react-embed';

const EmbedFlowExample: React.FunctionComponent = () => (
  <div>
    <EmbedFlow
      clientLabel="formsort"
      flowLabel="onboarding"
      variantLabel="main"
      queryParams={['variantRevisionUuid', '<uuidv4>']}
    />
  </div>
);
```


---

# 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://docs.formsort.com/publishing-and-deployment/embedding/web-embed-api/react-embed.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.
