Open History to see the last commit
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 })
35}