useIsMetricFieldConfigured
Returns whether a metric is selected in a metric
field, without subscribing to the metric.
function useIsMetricFieldConfigured(props: {field: string}): boolean
Arguments
| Property | Type | Description |
|---|---|---|
| field | string | The name of the field. |
Returns
true if a metric is selected, otherwise false.
Example
Use it to distinguish a widget that isn't configured yet from a widget waiting for its first value:
src/widgets/example/Example.tsx
import React from 'react'
import {Loading, MissingConfigPlaceholder, useIsMetricFieldConfigured, useMetricField} from '@modbros/dashboard-sdk'
export default function Example() {
const isConfigured = useIsMetricFieldConfigured({field: 'metric'})
const channelValue = useMetricField({field: 'metric'})
if (!isConfigured) {
return <MissingConfigPlaceholder text="Please select a metric"/>
}
if (!channelValue) {
return <Loading/>
}
return <span>{channelValue.value.value}</span>
}