You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .changeset/typegen-component-inference.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
"@portabletext/react": minor
3
3
---
4
4
5
-
# TypeGen-aware Portable Text components
5
+
TypeGen-aware Portable Text components
6
6
7
7
`<PortableText>` now infers the shape of every component handler from the `value` prop. When you pass a value typed by [Sanity TypeGen](https://www.sanity.io/docs/apis-and-sdks/sanity-typegen), `components.types`, `components.marks`, `components.block`, `components.list`, and `components.listItem` all receive precise `value` props for the exact content the query returned.
8
8
@@ -12,7 +12,7 @@ Three new utility types ship with this feature:
12
12
-`InferStrictComponents<T>` - strict variant that requires a handler for every inferred custom type, mark, block style, and list style, and rejects handlers that aren't in the schema (and therefore not visible to TypeGen).
13
13
-`InferValue<T>` - derives a Portable Text array value type from any TypeGen query result type, useful for re-usable wrapper components.
14
14
15
-
## Schema
15
+
####Schema
16
16
17
17
Every example below assumes the same `sanity.config.ts`:
18
18
@@ -50,7 +50,7 @@ export default defineConfig({
50
50
})
51
51
```
52
52
53
-
## Before: hand-typing handlers
53
+
####Before: hand-typing handlers
54
54
55
55
Previously, every handler had to be typed by hand to mirror the generated query shape:
## `InferStrictComponents` + `InferValue`: a strict, re-usable wrapper
205
+
####`InferStrictComponents` + `InferValue`: a strict, re-usable wrapper
206
206
207
207
`InferValue<SanityQueries[keyof SanityQueries]>` collects every Portable Text item shape from every registered TypeGen query into an array value type, and `InferStrictComponents` requires a handler for each of them. Together they're perfect for a single `CustomPortableText` you reuse across the app:
0 commit comments