import { type ReadonlySignal, type Signal } from '@preact/signals-core'; import { type Atom, type AtomLike, type AtomState, type Computed, type Ext, type Fn } from '@reatom/core'; export interface PreactExt { preact: Signal; } export interface PreactReadonlyExt { preact: ReadonlySignal; } /** * Converts Reatom atom to Preact signal. * * The signal is lazily connected to the atom - it subscribes to the atom only * when the signal itself gets subscribers (through Preact's component rendering * or effects). When all subscribers unsubscribe from the signal, the atom * subscription is also cleaned up. * * This function is safe to call multiple times for the same atom - if the atom * already has a `.preact` property (created by `withPreact`), it will return * the cached signal. Otherwise, it creates a new signal by extending the atom. * * This is particularly useful in JSX where you need to pass signals directly to * native elements or signal-aware components. * * @example * // Basic usage * const countAtom = atom(0, 'count') * const countSignal = toPreact(countAtom) * * // In Preact component: * return
{countSignal.value}
* * @example * // Direct JSX binding - can be called repeatedly in render * const inputAtom = atom('', 'input') * return * * @example * // With computed atoms (returns ReadonlySignal) * const doubleAtom = computed(() => countAtom() * 2, 'double') * const doubleSignal = toPreact(doubleAtom) // ReadonlySignal * * @param target - The Reatom atom to convert * @returns A Preact signal synchronized with the atom state. Returns `Signal` * for writable atoms and `ReadonlySignal` for computed atoms. */ export declare function toPreact(target: Atom): Signal; export declare function toPreact(target: Computed): ReadonlySignal; /** * Extension that adds `.preact` property with a Preact signal synchronized with * the target atom. * * The signal is lazily connected - it subscribes to the atom only when the * signal gets subscribers. This integrates with Preact's automatic dependency * tracking: accessing `.preact.value` in a component will re-render when the * atom changes. * * For writable atoms, the signal is also writable - setting `signal.value` will * update the atom. For computed atoms, the signal is read-only. * * @example * // Writable atom - signal is also writable * const countAtom = atom(0, 'count').extend(withPreact()) * countAtom.preact.value = 5 // Updates the atom * * // In Preact component: * return
{countAtom.preact.value}
* * @example * // Computed atom - signal is read-only * const doubleAtom = computed(() => countAtom() * 2, 'double').extend( * withPreact(), * ) * // doubleAtom.preact is ReadonlySignal * * @returns Extension that adds `.preact` property to the atom */ export declare function withPreact(): Ext> : PreactReadonlyExt>>; //# sourceMappingURL=signal.d.ts.map