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
{{ message }}
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Register a cleanup function that runs when the current reactive scope is disposed. Inside an `effect`, `onCleanup` runs before each re-execution and on final disposal. Inside a component, it runs when the component unmounts. This is the idiomatic way to clean up resources in effects.
608
+
609
+
```tsx
610
+
import {onCleanup} from "@pyreon/core"
611
+
import {signal, effect} from "@pyreon/reactivity"
612
+
613
+
function WebSocketComponent(props: {url: () =>string}) {
Register an error handler for the component subtree. When an error is thrown during rendering or in a child component, the nearest `onErrorCaptured` handler is called. Return `true` to mark the error as handled and stop propagation.
Split a props object into two parts: one with the specified keys, and one with the rest. Both parts preserve reactivity -- accessing a property on either part reads the original prop.
1480
+
1481
+
```tsx
1482
+
import {splitProps} from "@pyreon/core"
1483
+
1484
+
function Button(props: {label: string; icon?:string} & PyreonHTMLAttributes<HTMLButtonElement>) {
function splitProps<Textendsobject,KextendskeyofT>(
1500
+
props: T,
1501
+
keys: K[],
1502
+
): [Pick<T, K>, Omit<T, K>]
1503
+
```
1504
+
1505
+
### mergeProps
1506
+
1507
+
Merge multiple props objects into one, with later sources overriding earlier ones. The merged object is lazy -- property reads go through the original sources, preserving reactivity.
1508
+
1509
+
```tsx
1510
+
import {mergeProps} from "@pyreon/core"
1511
+
1512
+
function Button(props: {size?:"sm"|"md"|"lg"; variant?:string}) {
@@ -1780,4 +1889,31 @@ Dispatch an error to the nearest active `ErrorBoundary`. Returns `true` if the b
1780
1889
1781
1890
<APICardname="onUnmount"type="hook"signature="onUnmount(callback: () => void): void"description="Registers a callback to run when the component is removed from the DOM. Use for cleanup not covered by onMount's return value." />
1782
1891
1892
+
<APICardname="onCleanup"type="hook"signature="onCleanup(fn: () => void): void"description="Registers a cleanup function for the current reactive scope. Inside effects, runs before each re-execution and on disposal. Inside components, runs on unmount." />
1893
+
1783
1894
<APICardname="onUpdate"type="hook"signature="onUpdate(callback: () => void): void"description="Registers a callback to run after each reactive update within the component. Fires via microtask after effects settle, so the DOM is up-to-date." />
1895
+
1896
+
<APICardname="splitProps"type="function"signature="splitProps<T, K extends keyof T>(props: T, keys: K[]): [Pick<T, K>, Omit<T, K>]"description="Splits a props object into two parts preserving reactivity. First part has the specified keys, second has the rest." />
1897
+
1898
+
<APICardname="mergeProps"type="function"signature="mergeProps<T extends object[]>(...sources: T): MergedProps<T>"description="Merges multiple props objects with later sources overriding earlier ones. Preserves reactivity through lazy property access." />
1899
+
1900
+
<APICardname="createUniqueId"type="function"signature="createUniqueId(): string"description="Generates a unique string ID that is stable across server and client renders. Use for ARIA attributes and label-input linking." />
1901
+
1902
+
<APICardname="cx"type="function"signature="cx(...args: ClassValue[]): string"description="Utility for composing class names from strings, arrays, objects, or nested combinations. Used internally by the class prop." />
1903
+
1904
+
## Type Exports
1905
+
1906
+
| Type | Description |
1907
+
|------|-------------|
1908
+
| `ComponentFn<P>` | `(props: P) => VNodeChild` -- component function type |
1909
+
| `VNode` | Virtual DOM node with type, props, children, and key |
1910
+
| `VNodeChild` | Union type for all renderable values (VNode, string, number, null, boolean, function, array) |
1911
+
| `Props` | Base props interface for elements and components |
1912
+
| `Ref<T>` | Mutable ref container `{current: T \|null}` |
1913
+
| `ExtractProps<T>` | Extracts the props type from a `ComponentFn<P>`, or passes through if already a props object |
onCleanup(() =>controller.abort()) // runs before next re-execution
358
+
})
359
+
```
360
+
361
+
Alternatively, use `watch` when you need old/new values along with cleanup:
348
362
349
363
```ts
350
-
// Use watch for effects that need cleanup
351
364
watch(
352
365
() =>query(),
353
366
(q) => {
@@ -1160,12 +1173,12 @@ scope.runInScope(() => {
1160
1173
})
1161
1174
```
1162
1175
1163
-
## runUntracked
1176
+
## runUntracked/untrack
1164
1177
1165
-
Runafunction without registering any reactive dependencies. Useful inside effects when you need to read a signal without subscribing to it.
1178
+
Runafunction without registering any reactive dependencies. Useful inside effects when you need to read a signal without subscribing to it. `untrack` is a shorter alias for `runUntracked` -- both are identical.
<APICard name="runUntracked" type="function" signature="runUntracked<T>(fn: () => T): T" description="Runs a function without tracking any reactive dependencies." />
0 commit comments