# Dashboard runtime library

## Overview

The *Dashboard Runtime Library* written in [React](https://es.react.dev/), is the backbone that enables building applications within Ubidots with the capability of interacting with dashboard data, events and the Ubidots API.

## Getting started

### Add the library to your project

Run the following command at the root of the project where you want to add the library

{% tabs %}
{% tab title="PNPM" %}

```bash
pnpm add @ubidots/react-html-canvas
```

{% endtab %}

{% tab title="Yarn " %}

```bash
yarn add @ubidots/react-html-canvas
```

{% endtab %}
{% endtabs %}

#### Peer Dependencies

* react >= 16.8
* react-dom >= 16.8

### Usage

Wrap your app with the Provider and use hooks to access dashboard data/event

```js
import 
  UbidotsProvider,
  useUbidotsReady,
  useUbidotsSelectedDevice,
  useUbidotsActions,
} from '@ubidots/react-html-canvas';

function DeviceInfo() {
  const ready = useUbidotsReady();
  const device = useUbidotsSelectedDevice();
  const { setDashboardDevice } = useUbidotsActions();

  if (!ready) return <span>Loading...</span>;
  return (
    <div>
      <pre>{JSON.stringify(device, null, 2)}</pre>
      <button onClick={() => setDashboardDevice('device-id')}>
        Select Device
      </button>
    </div>
  );
}

export default function App() {
  return (
    <UbidotsProvider readyEvents={['receivedToken']}>
      <DeviceInfo />
    </UbidotsProvider>
  );
}
```

## API & examples

Go to the project's [repo](https://github.com/ubidots/react-html-canvas?tab=readme-ov-file) for understanding more about all the available hooks and actions that the library expose.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ubidots.com/sdks/dashboard-runtime-library.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
