useFieldConfig
Returns the definition of a field from the config array of the
mobro-widget-config.json, e.g. to access the options of a select field.
function useFieldConfig<T extends FieldBase>(props: {field: string}): T | null
Arguments
| Property | Type | Description |
|---|---|---|
| field | string | The name of the field. |
Returns
The field definition, or null if the widget has no field with this name. Only fields at the top level of the config
array are found, not the fields within a repeater.
The types of all field definitions, like FieldSelect or FieldMetric, are exported by @modbros/dashboard-core.
Example
src/widgets/example/Example.tsx
import React from 'react'
import {useFieldConfig, useSelectField} from '@modbros/dashboard-sdk'
import type {FieldSelect} from '@modbros/dashboard-core'
export default function Example() {
const fieldConfig = useFieldConfig<FieldSelect>({field: 'time_format'})
const value = useSelectField({field: 'time_format'})
const selectedOption = fieldConfig?.options.find((option) => option.value === value)
return <span>{selectedOption?.label}</span>
}