Dashboard runtime library
Overview
The Dashboard Runtime Library written in React, 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
pnpm add @ubidots/react-html-canvasyarn add @ubidots/react-html-canvasPeer Dependencies
react >= 16.8
react-dom >= 16.8
Usage
Wrap your app with the Provider and use hooks to access dashboard data/event
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
To build a dashboard widget with this library, see Custom Metric. Each dashboard capability has its own page with the exact payload shapes and a snippet:
Widget data:
useWidgetEvents()onInfo/onData.Devices:
dashboardDevices,useUbidotsSelectedDevice(),setDashboardDevice().Date range:
useUbidotsDashboardDateRange(),setDashboardDateRange().Real-time:
useUbidotsRealTimeStatus(),setRealTime().Dashboard actions and filters:
refreshDashboard(),setFullScreen(),openDrawer(),setDashboardLayer(),useUbidotsSelectedFilters().Widget events:
emitWidgetEvent(),onWidgetEvent(),onAnyWidgetEvent().
For the full list of hooks and actions the library exposes, see the project's repo.
Last updated
Was this helpful?