useRawField
Reads and updates the raw value of a field of any type, as stored by MoBro. All other field hooks are based on these two hooks.
Use them for field types without a dedicated hook, or when you need the value exactly as stored, e.g.
the ValueMetricConfig of a metric field instead of the metric's value.
function useRawField<T>(props: {field: string}): T | undefined
function useSetRawField<T>(props: {field: string}): SetterOrUpdater<T | undefined>
Arguments
| Property | Type | Description |
|---|---|---|
| field | string | The name of the field. |
Returns
useRawFieldreturns the stored value of the field, orundefinedif the field has no value. The typeTis not checked at runtime; see Types for the value types of the field types.useSetRawFieldreturns a setter function for the value of the field, see Setter Hooks.
Example
src/widgets/example/Example.tsx
import React from 'react'
import {useRawField, useSetRawField} from '@modbros/dashboard-sdk'
import type {ValueMetricConfig} from '@modbros/dashboard-core'
export default function Example() {
const metricConfig = useRawField<ValueMetricConfig>({field: 'metric'})
const setMetricConfig = useSetRawField<ValueMetricConfig>({field: 'metric'})
return (
<button onClick={() => setMetricConfig(undefined)}>
Clear metric {metricConfig?.id}
</button>
)
}