@fictjs/use-callback-ref
v0.3.4
Published
Ref utilities and stable callback helpers for Fict UI primitives.
Maintainers
Readme
@fictjs/use-callback-ref
Ref utilities and stable callback helpers for Fict. A toolkit for creating, merging, and transforming refs, plus a stable callback wrapper — combining ideas from @radix-ui/react-use-callback-ref and use-callback-ref.
Part of ui-primitives, a port of Radix Primitives to Fict.
Installation
pnpm add @fictjs/use-callback-ref fictUsage
import { prop } from 'fict'
import { useCallbackRef, mergeRefs } from '@fictjs/use-callback-ref'
// A stable function identity that always calls the latest callback:
const stable = useCallbackRef<(value: string) => void>(prop(() => props.onChange))
// Merge several refs into one:
const ref = mergeRefs([localRef, props.ref])API
useCallbackRef(callback)— a stable function whose identity never changes. A direct callback is retained as provided; when a parent can replace it, pass a Fict signal, computed value, orprop(() => callback)so each invocation reads the current callback. The latest callback is snapshotted during cleanup so deferred unmount work can still invoke it safely.createCallbackRef(cb)/assignRef(ref, value)— low-level callback-ref creation and assignment.mergeRefs(refs)/useMergeRefs(refs)— combine multiple refs into one.transformRef(ref, transform)/useTransformRef(...)— derive a ref whose value is a transform of another.refToCallback(ref)/useRefToCallback(ref)— adapt a ref object to a callback ref.
Exports
- Values:
useCallbackRef,createCallbackRef,assignRef,mergeRefs,useMergeRefs,transformRef,useTransformRef,refToCallback,useRefToCallback. - Types:
Ref,RefObject,RefCallback,RefLifecycleCallback,MaybeRef.
Documentation
See the ui-primitives overview and the architecture guide.
License
MIT © Fict contributors.
