This skill provides patterns for building forms using Sentry's new form system built on TanStack React Form and Zod validation.
Core Principle
Always use the new form system (
useScrapsForm
,
AutoSaveField
) for new forms. Never create new forms with the legacy JsonForm or Reflux-based systems.
All forms should be schema based. DO NOT create a form without schema validation.
Imports
All form components are exported from
@sentry/scraps/form
:
import
{
z
}
from
'zod'
;
import
{
AutoSaveField
,
defaultFormOptions
,
setFieldErrors
,
useScrapsForm
,
}
from
'@sentry/scraps/form'
;
Important
DO NOT import from deeper paths, like '@sentry/scraps/form/field'. You can only use what is part of the PUBLIC interface in the index file in @sentry/scraps/form.
Form Hook:
useScrapsForm
The main hook for creating forms with validation and submission handling.
Basic Usage
import
{
z
}
from
'zod'
;
import
{
defaultFormOptions
,
useScrapsForm
}
from
'@sentry/scraps/form'
;
const
schema
=
z
.
object
(
{
email
:
z
.
string
(
)
.
email
(
'Invalid email'
)
,
name
:
z
.
string
(
)
.
min
(
2
,
'Name must be at least 2 characters'
)
,
}
)
;
function
MyForm
(
)
{
const
form
=
useScrapsForm
(
{
...
defaultFormOptions
,
defaultValues
:
{
email
:
''
,
name
:
''
,
}
,
validators
:
{
onDynamic
:
schema
,
}
,
onSubmit
:
(
{
value
,
formApi
}
)
=>
{
// Handle submission
console
.
log
(
value
)
;
}
,
}
)
;
return
(
<
form.AppForm
form
=
{
form
}
>
<
form.AppField
name
=
"
email
"
>
{
field
=>
(
<
field.Layout.Stack
label
=
"
Email
"
required
>
<
field.Input
value
=
{
field
.
state
.
value
}
onChange
=
{
field
.
handleChange
}
/>
</
field.Layout.Stack
>
)
}
</
form.AppField
>
<
form.SubmitButton
>
Submit
</
form.SubmitButton
>
</
form.AppForm
>
)
;
}
Important
Always spread
defaultFormOptions
first. It configures validation to run on submit initially, then on every change after the first submission. This is why validators are defined as
onDynamic
, and it's what provides a consistent UX.
Returned Properties
Property
Description
AppForm
Root wrapper component (provides form context and renders