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

inject-selector.ts

19 lines785 Bytes

1import { injectSelector as injectAngularSelector } from '@tanstack/angular-store'
2import type { Signal } from '@angular/core'
3import type { FormApi, FormErrorTypes, FormState } from '@tanstack/form-core'
4import type { InjectSelectorOptions } from '@tanstack/angular-store'
5​
6/** Selects form state as an Angular signal. */
7export function injectSelector<
8 TFormData,
9 TFormErrorTypes extends FormErrorTypes,
10 TSelected = NoInfer<FormState<TFormData, TFormErrorTypes>>,
11>(
12 form: FormApi<TFormData, TFormErrorTypes>,
13 selector: (
14 state: NoInfer<FormState<TFormData, TFormErrorTypes>>,
15 ) => TSelected = (state) => state as unknown as TSelected,
16 options?: InjectSelectorOptions<TSelected>,
17): Signal<TSelected> {
18 return injectAngularSelector(form.atom, selector, options)