Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

useFieldDetailValues.ts

35 lines851 Bytes

1import { createMemo } from 'solid-js'
2import type { FieldId } from '@/types/branded'
3import { useFormDevtoolsStore } from '@/stores/formDevtoolsStore'
4​
5type FieldDetailValuesState =
6 | { status: 'disabled' }
7 | { status: 'pending' }
8 | {
9 status: 'ready'
10 value: unknown
11 defaultValue: unknown
12 }
13​
14export function useFieldDetailValues(fieldId: FieldId) {
15 const { getFieldDetail, getFieldDetailSettings } =
16 useFormDevtoolsStore().fieldDetails
17​
18 return createMemo((): FieldDetailValuesState => {
19 if (!getFieldDetailSettings(fieldId).includeValues) {
20 return { status: 'disabled' }
21 }
22​
23 const detail = getFieldDetail(fieldId)
24​
25 if (!detail) {
26 return { status: 'pending' }
27 }
28​
29 return {
30 status: 'ready',
31 value: detail.state.value,
32 defaultValue: detail.defaultValue,
33 }
34 })