Skip to content

Commit 835543c

Browse files
authored
docs(form): Effect Schema also supports Standard Schema (#1259)
* Update validation.md Effect Schema also supports Standard Schema * Add validation by Effect/Schema to react example * ci: apply automated fixes and generate docs
1 parent 5b2c9cc commit 835543c

4 files changed

Lines changed: 294 additions & 158 deletions

File tree

docs/framework/react/guides/validation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ TanStack Form natively supports all libraries following the [Standard Schema spe
446446
- [Zod](https://zod.dev/)
447447
- [Valibot](https://valibot.dev/)
448448
- [ArkType](https://arktype.io/)
449+
- [Effect/Schema](https://effect.website/docs/schema/standard-schema/)
449450
450451
_Note:_ make sure to use the latest version of the schema libraries as older versions might not support Standard Schema yet.
451452

examples/react/standard-schema/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"@tanstack/react-form": "^1.2.4",
1313
"arktype": "^2.1.15",
14+
"effect": "^3.13.8",
1415
"react": "^19.0.0",
1516
"react-dom": "^19.0.0",
1617
"valibot": "^1.0.0",

examples/react/standard-schema/src/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as React from 'react'
44
import { createRoot } from 'react-dom/client'
55
import * as v from 'valibot'
66
import { z } from 'zod'
7+
import { Schema as S } from 'effect'
78
import type { AnyFieldApi } from '@tanstack/react-form'
89

910
function FieldInfo({ field }: { field: AnyFieldApi }) {
@@ -42,6 +43,23 @@ const ArkTypeSchema = type({
4243
lastName: 'string >= 3',
4344
})
4445

46+
const EffectSchema = S.standardSchemaV1(
47+
S.Struct({
48+
firstName: S.String.pipe(
49+
S.minLength(3),
50+
S.annotations({
51+
message: () => '[Effect/Schema] You must have a length of at least 3',
52+
}),
53+
),
54+
lastName: S.String.pipe(
55+
S.minLength(3),
56+
S.annotations({
57+
message: () => '[Effect/Schema] You must have a length of at least 3',
58+
}),
59+
),
60+
}),
61+
)
62+
4563
export default function App() {
4664
const form = useForm({
4765
defaultValues: {
@@ -53,6 +71,7 @@ export default function App() {
5371
onChange: ZodSchema,
5472
// onChange: ValibotSchema,
5573
// onChange: ArkTypeSchema,
74+
// onChange: EffectSchema,
5675
},
5776
onSubmit: async ({ value }) => {
5877
// Do something with form data

0 commit comments

Comments
 (0)