Skip to main content

Embedding in React

The embedding instructions for capabilities always look something like this:

<script src=""></script>
<capability-name-device id="user123" jwt="[JWT]" host="" ssl="true" />

but when using React, you may wonder how to dynamically load that script, because React does not correctly interpret script tags in components.

The recommended solution is to dynamically add the script tag to your document head at run-time. You can follow this example:

import { useEffect } from 'react';

/** ensure the named web component is loaded; if not, it is loaded assuming
the .js file it is defined in has the same name as the component itself */
export const ensureWebComponentIsLoaded = (capability, name, userId, deviceId) => {
useEffect(() => {
if (userId && deviceId && !customElements.get(name)) {
const host = '';
const script = document.createElement('script');
const params = `userId=${userId}&deviceId=${deviceId}`;
}, [capability, name, userId, deviceId]);

In this function:

  • capability is the name of the capability you want to embed, e.g., @transitive-robotics/webrtc-video.
  • name is the name of the web component in that capability, e.g., webrtc-video-device, or configuration-management-fleet.
  • userId is your user Id on
  • deviceId is the Id of the device for which you want to load the component.