useNumberField
Reads the value of a number field.
function useNumberField(props: {field: string; defaultValue?: number}): number | null
Arguments
| Property | Type | Description |
|---|---|---|
| field | string | The name of the field. |
| defaultValue | number | The value returned while the field is empty. |
Returns
The number the user entered. If the field is empty, the defaultValue, or null without a defaultValue.
Example
src/widgets/example/Example.tsx
import React from 'react'
import {useNumberField} from '@modbros/dashboard-sdk'
export default function Example() {
const fontSize = useNumberField({field: 'font_size', defaultValue: 16})
return <span style={{fontSize: fontSize ?? undefined}}>Sized text</span>
}