useSelectField
Reads the value of a select
or radio field.
function useSelectField(props: {field: string; defaultValue?: string}): string | null
Arguments
| Property | Type | Description |
|---|---|---|
| field | string | The name of the field. |
| defaultValue | string | The 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>
}