> For the complete documentation index, see [llms.txt](https://dev.ubidots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.ubidots.com/dashboards-and-widgets/custom-metric/project-setup.md).

# Project setup

Custom Metric widget project setup — main.jsx entry, UbidotsProvider mounting into

A Custom Metric widget is a small React app. Its files are:

* `main.jsx`: the entry point.
* `Widget.jsx` and other components (optional).
* `style.css`.
* `package.json`.
* `manifest.toml`.

The compiled output is `script.js`, plus `style.css`.

## Entry and mounting (`main.jsx`)

```jsx
import React from 'react';
import { createRoot } from 'react-dom/client';
import { UbidotsProvider } from '@ubidots/react-html-canvas';
import Widget from './Widget.jsx';
import './style.css';

// In production the widget id comes from the URL (?id=...); in the editor preview the
// host injects window.__UBIDOTS_WIDGET_ID__. Read both, in that order.
const widgetId =
  window.__UBIDOTS_WIDGET_ID__ ||
  new URLSearchParams(window.location.search).get('id') ||
  undefined;

createRoot(document.getElementById('root')).render(
  <UbidotsProvider widgetId={widgetId}>
    <Widget />
  </UbidotsProvider>
);
```

`UbidotsProvider` props:

| Prop                   | Description                                                                                 |
| ---------------------- | ------------------------------------------------------------------------------------------- |
| `widgetId`             | The widget's id, read as shown above.                                                       |
| `readyEvents`          | The inbound events the widget waits for before it is "ready". Default: `['receivedToken']`. |
| `onReady`              | Called when the widget is ready.                                                            |
| `validateOrigin`       | `(origin: string) => boolean`, to accept messages only from trusted origins.                |
| `initialStateOverride` | Initial state, mostly for tests.                                                            |

The app mounts into the existing `<div id="root"></div>`, which the bundler generates automatically.

## `manifest.toml`

Declare the compiled assets:

```toml
[page]
js_libraries = [{src="script.js", type="module", defer="", crossorigin=""}]
css_libraries = [{href="style.css", crossorigin=""}]
```

{% hint style="warning" %}
Without these entries the widget renders blank.
{% endhint %}

The `[page.settings]` block holds the widget's metadata. Keep its existing keys.

## `package.json`

Pin `"@ubidots/react-html-canvas": "0.3.0"`, plus `react` and `react-dom`. Other packages resolve through [esm.sh](https://esm.sh). Add them only when you need them.


---

# 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://dev.ubidots.com/dashboards-and-widgets/custom-metric/project-setup.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.
