File: standard-schema.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
Solid
Version
v1
Search...
+ K
Menu
Getting Started
Guides
API Reference
Examples
Framework
Solid
Version
v1
Menu
Getting Started
Guides
API Reference
Examples
Solid Example: Standard Schema
==================================================================================================================================================================================================================================================================================================================================================================================================================================
Code ExplorerCode
Interactive SandboxSandbox
src
index.tsx
vite-env.d.ts
.gitignore
README.md
index.html
package.json
tsconfig.json
vite.config.ts
tsx
/* @refresh reload */
import { render } from 'solid-js/web'
import { createForm } from '@tanstack/solid-form'
import { type } from 'arktype'
import * as v from 'valibot'
import { z } from 'zod'
import { Schema as S } from 'effect'
import type { AnyFieldApi } from '@tanstack/solid-form'
const ZodSchema = z.object({
firstName: z
.string()
.min(3, '[Zod] You must have a length of at least 3')
.startsWith('A', "[Zod] First name must start with 'A'"),
lastName: z.string().min(3, '[Zod] You must have a length of at least 3'),
})
const ValibotSchema = v.object({
firstName: v.pipe(
v.string(),
v.minLength(3, '[Valibot] You must have a length of at least 3'),
v.startsWith('A', "[Valibot] First name must start with 'A'"),
),
lastName: v.pipe(
v.string(),
v.minLength(3, '[Valibot] You must have a length of at least 3'),
),
})
const ArkTypeSchema = type({
firstName: 'string >= 3',
lastName: 'string >= 3',
})
const EffectSchema = S.standardSchemaV1(
S.Struct({
firstName: S.String.pipe(
S.minLength(3),
S.annotations({
message: () => '[Effect/Schema] You must have a length of at least 3',
}),
),
lastName: S.String.pipe(
S.minLength(3),
S.annotations({
message: () => '[Effect/Schema] You must have a length of at least 3',
}),
),
}),
)
interface FieldInfoProps {
field: AnyFieldApi
}
function FieldInfo(props: FieldInfoProps) {
return (
<>
{props.field.state.meta.isTouched && !props.field.state.meta.isValid ? (
<em>
{props.field.state.meta.errors.map((err) => err.message).join(',')}
</em>
) : null}
{props.field.state.meta.isValidating ? 'Validating...' : null}
</>
)
}
function App() {
const form = createForm(() => ({
defaultValues: {
firstName: '',
lastName: '',
},
validators: {
// DEMO: You can switch between schemas seamlessly
onChange: ZodSchema,
// onChange: ValibotSchema,
// onChange: ArkTypeSchema,
// onChange: EffectSchema,
},
onSubmit: async ({ value }) => {
// Do something with form data
console.log(value)
},
}))
return (
<div>
<h1>Simple Form Example</h1>
<form
onSubmit={(e) => {
e.preventDefault()
e.stopPropagation()
form.handleSubmit()
}}
>
<div>
{/* A type-safe field component*/}
<form.Field
name="firstName"
children={(field) => {
// Avoid hasty abstractions. Render props are great!
return (
<>
<label for={field().name}>First Name:</label>
<input
id={field().name}
name={field().name}
value={field().state.value}
onBlur={field().handleBlur}
onInput={(e) => field().handleChange(e.target.value)}
/>
<FieldInfo field={field()} />
</>
)
}}
/>
</div>
<div>
<form.Field
name="lastName"
children={(field) => (
<>
<label for={field().name}>Last Name:</label>
<input
id={field().name}
name={field().name}
value={field().state.value}
onBlur={field().handleBlur}
onInput={(e) => field().handleChange(e.target.value)}
/>
<FieldInfo field={field()} />
</>
)}
/>
</div>
<form.Subscribe
selector={(state) => ({
canSubmit: state.canSubmit,
isSubmitting: state.isSubmitting,
})}
children={(state) => {
return (
<button type="submit" disabled={!state().canSubmit}>
{state().isSubmitting ? '...' : 'Submit'}
</button>
)
}}
/>
</form>
</div>
)
}
const root = document.getElementById('root')
render(() => <App />, root!)
/* @refresh reload */
import { render } from 'solid-js/web'
import { createForm } from '@tanstack/solid-form'
import { type } from 'arktype'
import * as v from 'valibot'
import { z } from 'zod'
import { Schema as S } from 'effect'
import type { AnyFieldApi } from '@tanstack/solid-form'
const ZodSchema = z.object({
firstName: z
.string()
.min(3, '[Zod] You must have a length of at least 3')
.startsWith('A', "[Zod] First name must start with 'A'"),
lastName: z.string().min(3, '[Zod] You must have a length of at least 3'),
})
const ValibotSchema = v.object({
firstName: v.pipe(
v.string(),
v.minLength(3, '[Valibot] You must have a length of at least 3'),
v.startsWith('A', "[Valibot] First name must start with 'A'"),
),
lastName: v.pipe(
v.string(),
v.minLength(3, '[Valibot] You must have a length of at least 3'),
),
})
const ArkTypeSchema = type({
firstName: 'string >= 3',
lastName: 'string >= 3',
})
const EffectSchema = S.standardSchemaV1(
S.Struct({
firstName: S.String.pipe(
S.minLength(3),
S.annotations({
message: () => '[Effect/Schema] You must have a length of at least 3',
}),
),
lastName: S.String.pipe(
S.minLength(3),
S.annotations({
message: () => '[Effect/Schema] You must have a length of at least 3',
}),
),
}),
)
interface FieldInfoProps {
field: AnyFieldApi
}
function FieldInfo(props: FieldInfoProps) {
return (
<>
{props.field.state.meta.isTouched && !props.field.state.meta.isValid ? (
<em>
{props.field.state.meta.errors.map((err) => err.message).join(',')}
</em>
) : null}
{props.field.state.meta.isValidating ? 'Validating...' : null}
</>
)
}
function App() {
const form = createForm(() => ({
defaultValues: {
firstName: '',
lastName: '',
},
validators: {
// DEMO: You can switch between schemas seamlessly
onChange: ZodSchema,
// onChange: ValibotSchema,
// onChange: ArkTypeSchema,
// onChange: EffectSchema,
},
onSubmit: async ({ value }) => {
// Do something with form data
console.log(value)
},
}))
return (
<div>
<h1>Simple Form Example</h1>
<form
onSubmit={(e) => {
e.preventDefault()
e.stopPropagation()
form.handleSubmit()
}}
>
<div>
{/* A type-safe field component*/}
<form.Field
name="firstName"
children={(field) => {
// Avoid hasty abstractions. Render props are great!
return (
<>
<label for={field().name}>First Name:</label>
<input
id={field().name}
name={field().name}
value={field().state.value}
onBlur={field().handleBlur}
onInput={(e) => field().handleChange(e.target.value)}
/>
<FieldInfo field={field()} />
</>
)
}}
/>
</div>
<div>
<form.Field
name="lastName"
children={(field) => (
<>
<label for={field().name}>Last Name:</label>
<input
id={field().name}
name={field().name}
value={field().state.value}
onBlur={field().handleBlur}
onInput={(e) => field().handleChange(e.target.value)}
/>
<FieldInfo field={field()} />
</>
)}
/>
</div>
<form.Subscribe
selector={(state) => ({
canSubmit: state.canSubmit,
isSubmitting: state.isSubmitting,
})}
children={(state) => {
return (
<button type="submit" disabled={!state().canSubmit}>
{state().isSubmitting ? '...' : 'Submit'}
</button>
)
}}
/>
</form>
</div>
)
}
const root = document.getElementById('root')
render(() => <App />, root!)
