Skip to main content

useSelectField

Reads the value of a select or radio field.

function useSelectField(props: {field: string; defaultValue?: string}): string | null

Arguments​

PropertyTypeDescription
fieldstringThe name of the field.
defaultValuestringThe value returned while no option is selected.

Returns​

The value of the selected option. If no option is selected, the defaultValue, or null without a defaultValue.

Example​

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

export default function Example() {
const timeFormat = useSelectField({field: 'time_format', defaultValue: '24h'})

return <span>{new Date().toLocaleTimeString([], {hour12: timeFormat === '12h'})}</span>
}