Skip to main content

useMetricField

Field hook to access the data of a configurable field with the type metric. If the metric is configured the hook will automatically listen to changes to this metric value and trigger a re-render.

tip

This hook also updates even if the new value of the metric didn't change. So use this hook if you know you want to re-render every time a new value comes in, which is the polling frequency. If you only care about the value if it changed to reduce unnecessary re-renders, consider using useMemoizedMetricField

Arguments

The hook can take an object as argument with the following properties.

FieldTypeDescription
fieldstringThe name of the field

Returns

The ChannelValue for the metric.

Example

src/widgets/example/Example.tsx
import React from 'react'
import {useMetricField, ChannelValue} from '@modbros/dashboard-sdk'

export default function Example() {
const channelValue: ChannelValue | null = useMetricField({field: 'example'})

return null
}