Derived hooks compose Fraxel’s native hooks to provide domain-specific abstractions for common patterns. They don’t introduce new engine functionality — every derived hook is expressible usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/fraxel/llms.txt
Use this file to discover all available pages before exploring further.
useSignal, useComputed, useEvent, and useNode directly. They exist to eliminate boilerplate for patterns that appear repeatedly in game components: toggling booleans on opposing events, mapping signal values through records, and wiring up physics and animation nodes with reactive state.
All derived hooks are exported from fraxel/hooks alongside the core hooks.
Every node-specific derived hook (
useClickable, useTimer, useRayCast, useCollider, useAnimation, useAudio) accepts an optional ref parameter. If you pass an existing NodeReference, the hook uses it as-is. If you omit the parameter, the hook creates a new NodeReference internally via usePartialNode. This lets you share a single node reference across multiple hooks or use the derived hook as a self-contained unit.Quick Reference
| Hook | Description | Returns |
|---|---|---|
useCondition | Reactive boolean toggled by two opposing node events | SignalGetter<boolean> |
useMatch | Maps a signal value to a record — like a reactive switch | SignalGetter<U> |
useWhen | Ternary expression for signals | SignalGetter<T> |
useClickable | Clickable node with reactive hover state and mouse position | { ref, hovered, position } |
useTimer | Timer node with reactive time/progress and controls | { ref, time, progress, play, pause, stop } |
useRayCast | RayCast node with reactive detected state and collider | { ref, detected, collider } |
useCollider | Collider node with reactive collision state and collider set | { ref, colliding, detectedColliders } |
useAnimation | AnimationPlayer with reactive animation state and controls | { ref, animName, frameIndex, ended, play, stop, setNext } |
useAudio | AudioPlayer with reactive playing state and controls | { ref, playing, play, pause, stop } |
usePartialNode | Returns the provided ref or creates a new one | NodeReference<T> |
useCondition
true and false based on two opposing events fired by the same node. Internally composes useSignal and two useEvent calls. Use it any time you need a boolean that mirrors an “on/off” pair of events — hover state, detection state, active zones, etc.
The node that emits both events.
The event name that sets the condition to
true. Must be a valid event for the node type.The event name that sets the condition to
false. Must be a valid event for the node type.The initial value before either event fires. Defaults to
false.A reactive getter that returns
true after the agreeEvent fires and false after the disagreeEvent fires.useSignal, useEvent
useMatch
switch or match expression. Internally composes useComputed. If the current signal value is not a key in the record, defaultValue is returned (or undefined if not provided).
Both record and defaultValue accept Reactive<T> — either a plain value or a SignalGetterLike, so the record itself can be reactive.
A signal getter (or any zero-argument function) whose return value is used as the lookup key.
A record mapping possible signal values to output values. Can be a plain object or a signal getter returning an object.
The value to return when the signal value is not found in the record. Can be a plain value or a signal getter.
A reactive getter reflecting the matched value, updating whenever the input signal changes.
useWhen
whenTrue or whenFalse based on a boolean signal — a reactive ternary expression. Internally composes useComputed. Both whenTrue and whenFalse accept Reactive<T>, so they can be plain values or signal getters.
The boolean signal controlling which value to return.
The value (or reactive getter) to return when the signal is
true.The value (or reactive getter) to return when the signal is
false.A reactive getter that returns
whenTrue() or whenFalse() based on the current signal value.useClickable
Clickable node with reactive hover state and mouse position tracking. Internally creates a NodeReference (or reuses a provided one), then composes useCondition for hovered and useEvent for position.
An optional existing
NodeReference to the Clickable node. If omitted, a new reference is created.The node reference to pass to the
<clickable> element’s ref prop.true while the pointer is over the clickable area; false otherwise.The current pointer position over the clickable area, updated on every
mouseOver event.useCondition, /api/nodes-2d
useTimer
Timer node with reactive time and progress signals plus imperative controls. time updates on every timeChanged event. progress is a computed value — time() / duration — clamped between 0 and 1 relative to the timer’s duration prop.
An optional existing
NodeReference to the Timer node. If omitted, a new reference is created.The node reference to pass to the
<timer> element’s ref prop.The current elapsed time in seconds, updated reactively as the timer runs.
A
0–1 ratio of elapsed time to total duration. Computed as time() / duration.Starts or resumes the timer. Delegates to the underlying
Timer node’s play method.Pauses the timer without resetting it.
Stops the timer and resets elapsed time to zero.
/api/nodes-utility
useRayCast
RayCast node with reactive detection state. collider updates whenever the ray starts or stops intersecting a collider. detected is a computed boolean derived from collider() != null.
An optional existing
NodeReference to the RayCast node. If omitted, a new reference is created.The node reference to pass to the
<ray-cast> element’s ref prop.true while the ray is intersecting at least one collider; computed as collider() != null.The most recently detected
Collider instance, or null when nothing is intersected.useCondition, /api/nodes-2d
useCollider
Collider node with reactive collision tracking. Maintains a Set of all currently overlapping colliders — each entry or exit event creates a new Set instance so signal updates are triggered correctly. colliding is a computed signal derived as detectedColliders() != null. To check whether any collisions are active, test detectedColliders().size > 0 directly.
An optional existing
NodeReference to the Collider node. If omitted, a new reference is created.The node reference to pass to the
<collider> element’s ref prop.Computed as
detectedColliders() != null. Since detectedColliders is always a Set, use detectedColliders().size > 0 to test whether any colliders are currently overlapping.A reactive
Set of all Collider instances currently overlapping this collider. Each entry/exit creates a new Set instance to trigger reactive updates./api/nodes-2d
useAnimation
AnimationPlayer node with reactive animation state and imperative controls. All signals update as animation events fire on the node.
An optional existing
NodeReference to the AnimationPlayer node. If omitted, a new reference is created.The node reference to pass to the
<animation-player> element’s ref prop.The name of the currently playing animation, or
null when the animation is stopped. Updates on animationChanged and cleared on animationStopped.The zero-based index of the currently displayed frame. Updates on every
animationIndexChanged event.true after the current animation reaches its last frame (animationEnded), reset to false when a new animation starts (animationChanged). Composed via useCondition.Starts playback. Delegates to the underlying
AnimationPlayer.play method.Stops playback and clears the current animation.
Queues an animation to play after the current one finishes. Delegates to
AnimationPlayer.setNext.useCondition, /api/nodes-2d
useAudio
AudioPlayer node with a reactive playing boolean and imperative playback controls. playing is composed via useCondition — it becomes true on the started event and false on the ended event.
An optional existing
NodeReference to the AudioPlayer node. If omitted, a new reference is created.The node reference to pass to the
<audio-player> element’s ref prop.true while audio is playing. Toggles reactively between started and ended events.Starts or resumes audio playback.
Pauses playback without resetting position.
Stops playback and resets position.
useCondition, /api/nodes-utility
usePartialNode
NodeReference is provided and is an instance of NodeReference, it is returned as-is. Otherwise, a new NodeReference is created via useNode. This is what powers the optional ref parameter pattern throughout the derived hook API.
usePartialNode is an internal implementation detail and is not exported from fraxel/hooks. It is not part of the public API. The example below shows how it is used internally when building custom derived hooks in the same package.The node type to create if no existing reference is provided.
An optional existing
NodeReference to reuse. If provided and is a NodeReference instance, returned directly without calling useNode.Either the provided reference or a freshly created one.
usePartialNode is an internal implementation detail of the derived hook system and is not part of the public fraxel/hooks API. In your own game code, use one of the higher-level hooks (useClickable, useTimer, etc.) directly. If you are writing a custom derived hook, replicate the pattern shown above using useNode and instanceof NodeReference.useNode, /api/hooks-core, /guide/hooks, /guide/reactivity