Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit ba4790f

Browse files
vitbokischclaude
andcommitted
docs: update for @pyreon/core 0.7 — provide() API and VNodeChild return type
- Add provide() section to core context docs - Update coolgrid docs: pushContext → provide() - Update runtime-server component examples to use provide() - Fix ComponentFn return type: VNode | null → VNodeChild Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a1fad22 commit ba4790f

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

content/docs/coolgrid/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ You can customize the column count to any number (e.g., 24 columns for finer con
5858

5959
The grid uses Pyreon's context system to cascade configuration from parent to child:
6060

61-
1. **Container** sets the grid config (columns, gap, gutter, padding) and provides it via context using `pushContext`.
62-
2. **Row** reads the Container's config from context via `useContext`. It can override `columns` and `gap`. Row then pushes its own config into context for child columns.
61+
1. **Container** sets the grid config (columns, gap, gutter, padding) and provides it via context using `provide()`.
62+
2. **Row** reads the Container's config from context via `useContext`. It can override `columns` and `gap`. Row then provides its own config into context for child columns.
6363
3. **Col** reads the Row's config from context to calculate its width percentage and internal padding.
6464

6565
This means you configure the grid once at the Container level, and Rows and Cols automatically inherit those settings. If you need a Row with different settings, you can override them at the Row level.

content/docs/core/index.mdx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Pyreon components are typed using the `ComponentFn` type, which is a generic fun
126126
import type { ComponentFn, Props, VNode, VNodeChild } from "@pyreon/core"
127127

128128
// The ComponentFn type
129-
type ComponentFn<P extends Props = Props> = (props: P) => VNode | null
129+
type ComponentFn<P extends Props = Props> = (props: P) => VNodeChild
130130

131131
// Type your props explicitly
132132
interface UserCardProps {
@@ -694,6 +694,35 @@ function ThemedButton() {
694694
}
695695
```
696696

697+
### provide
698+
699+
Provide a context value to all descendants. Automatically handles cleanup on unmount. This is the recommended way to provide context inside components.
700+
701+
```tsx
702+
import { createContext, provide, useContext } from "@pyreon/core"
703+
704+
const ThemeContext = createContext("light")
705+
706+
function ThemeProvider(props: { mode: string; children: VNodeChild }) {
707+
provide(ThemeContext, props.mode)
708+
return <>{props.children}</>
709+
}
710+
711+
function ThemedContent() {
712+
const mode = useContext(ThemeContext) // "dark"
713+
return <div class={mode}>Themed content</div>
714+
}
715+
716+
// Usage
717+
<ThemeProvider mode="dark">
718+
<ThemedContent />
719+
</ThemeProvider>
720+
```
721+
722+
<Callout type="info">
723+
`provide()` must be called during component setup (synchronously inside a component function). For SSR or test contexts outside component lifecycle, use the lower-level `pushContext`/`popContext` APIs.
724+
</Callout>
725+
697726
### withContext
698727

699728
Provide a value for a context during a function execution. Used internally by the renderer when it encounters a provider component.
@@ -1714,7 +1743,7 @@ Runs a component function in a tracked context so lifecycle hooks registered ins
17141743
function runWithHooks<P extends Props>(
17151744
fn: ComponentFn<P>,
17161745
props: P,
1717-
): { vnode: VNode | null; hooks: LifecycleHooks }
1746+
): { vnode: VNodeChild; hooks: LifecycleHooks }
17181747
```
17191748

17201749
### propagateError

content/docs/runtime-server/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ app.get("/page-b", async (req, res) => {
107107
Even with 50+ concurrent requests and async components that resolve in unpredictable order, each render sees only its own context values:
108108

109109
```tsx
110-
import { createContext, pushContext, useContext } from "@pyreon/core"
110+
import { createContext, provide, useContext } from "@pyreon/core"
111111

112112
const RequestIdCtx = createContext("none")
113113

@@ -118,7 +118,7 @@ async function AsyncReader(props: { delay: number }) {
118118
}
119119

120120
function RequestWrapper(props: { reqId: string; delay: number }) {
121-
pushContext(new Map([[RequestIdCtx.id, props.reqId]]))
121+
provide(RequestIdCtx, props.reqId)
122122
return <AsyncReader delay={props.delay} />
123123
}
124124

@@ -394,7 +394,7 @@ Suspense boundary resolutions inherit the context stack from their parent scope.
394394
const ThemeCtx = createContext("light")
395395

396396
function App() {
397-
pushContext(new Map([[ThemeCtx.id, "dark"]]))
397+
provide(ThemeCtx, "dark")
398398
return (
399399
<Suspense fallback={<p>Loading...</p>}>
400400
<AsyncContent />{/* useContext(ThemeCtx) returns "dark" */}

0 commit comments

Comments
 (0)