Skip to main content

useSliderField

Reads the value of a slider field.

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

Arguments​

PropertyTypeDescription
fieldstringThe name of the field.
defaultValuenumberThe value returned while the field isn't set.

Returns​

The number users picked. If the field isn't set, the defaultValue, or null without a defaultValue.

The value is within min and max of the field when users pick it in the dashboard builder. Values set by a setter aren't checked, so clamp the value if your widget relies on the range.

Example​

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

export default function Example() {
const opacity = useSliderField({field: 'opacity', defaultValue: 1})

return <div style={{opacity: opacity ?? 1}}>Faded content</div>
}

Setter​

useSetSliderField({field}) returns a setter to change the value from within the widget, see Setter Hooks.