Skip to content

Commit 18df298

Browse files
committed
chore: move useTransform to adapters and remove it from core
1 parent 95fcd2e commit 18df298

File tree

9 files changed

+52
-1
lines changed

9 files changed

+52
-1
lines changed

packages/react-form-nextjs/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from '@tanstack/react-form'
22

33
export * from './createServerValidate'
44
export * from './error'
5+
export * from './useTransform'
File renamed without changes.

packages/react-form-remix/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from '@tanstack/react-form'
22

33
export * from './createServerValidate'
44
export * from './error'
5+
export * from './useTransform'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { AnyFormApi, FormTransform } from '@tanstack/form-core'
2+
3+
export function useTransform(
4+
fn: (formBase: AnyFormApi) => AnyFormApi,
5+
deps: unknown[],
6+
): FormTransform<any, any, any, any, any, any, any, any, any, any, any, any> {
7+
return {
8+
fn,
9+
deps,
10+
}
11+
}
File renamed without changes.

packages/react-form-start/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from '@tanstack/react-form'
33
export * from './createServerValidate'
44
export * from './getFormData'
55
export * from './error'
6+
export * from './useTransform'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { AnyFormApi, FormTransform } from '@tanstack/form-core'
2+
3+
export function useTransform(
4+
fn: (formBase: AnyFormApi) => AnyFormApi,
5+
deps: unknown[],
6+
): FormTransform<any, any, any, any, any, any, any, any, any, any, any, any> {
7+
return {
8+
fn,
9+
deps,
10+
}
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expectTypeOf, it } from 'vitest'
2+
import { formOptions, mergeForm, useForm, useTransform } from '../src'
3+
import type { ServerFormState } from '../src'
4+
5+
it('should maintain the type of the form', () => {
6+
const state = {} as ServerFormState<any, any>
7+
8+
const formOpts = formOptions({
9+
defaultValues: {
10+
firstName: '',
11+
age: 123,
12+
} as const,
13+
})
14+
15+
function Comp() {
16+
const form = useForm({
17+
...formOpts,
18+
transform: useTransform(
19+
(baseForm) => mergeForm(baseForm, state),
20+
[state],
21+
),
22+
})
23+
24+
expectTypeOf(form.state.values.age).toEqualTypeOf<123>()
25+
expectTypeOf(form.state.values.firstName).toEqualTypeOf<''>()
26+
}
27+
})

packages/react-form/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ export * from './types'
77
export * from './useField'
88
export * from './useFieldGroup'
99
export * from './useForm'
10-
export * from './useTransform'

0 commit comments

Comments
 (0)