Open History to see the last commit
1import { useSelector } from '@tanstack/preact-store'
2import { useMemo } from 'preact/compat'
3import type { AnyInternalFieldApi } from '@tanstack/form-core/internals'
4β
5export function useValueFieldSubscription(
6 fieldApi: AnyInternalFieldApi,
7): AnyInternalFieldApi {
8 const value = useSelector(fieldApi.atom, (state) => state.value)
9 const meta = useSelector(fieldApi.atom, (state) => state.meta)
10β
11 return useMemo(() => {
12 void meta
13 void value
14 return Object.create(fieldApi)
15 }, [fieldApi, meta, value])
16}
17β
18export function useArrayFieldSubscription(
19 fieldApi: AnyInternalFieldApi,
20): AnyInternalFieldApi {
21 const length = useSelector(fieldApi.atom, (state) => state.value.length)
22 const arrayVersion = useSelector(
23 fieldApi.atom,
24 (state) => state.meta._arrayVersion,
25 )
26β
27 return useMemo(() => {
28 void length
29 void arrayVersion
30 return Object.create(fieldApi)
31 }, [fieldApi, arrayVersion, length])
32}