Skip to content

pretty fusion utils

Spread the joy of Fusion

pretty-fusion-utils is an opinionated collection of useful Fusion 0.3 utilities, borrowed from Vide and React hooks.

useCamera

Returns a state object with the current camera. Updates when the current camera changes.

useCleanup

Add clean up tasks to the scope. Returns the clean up tasks, allowing it to be used in declarations.

useCoroutine

Spawns a new coroutine that is closed once the scope is cleaned up.

useEffect

Perform side effects with state objects.

useEventListener

Connects to an event-like object. The connection is automatically disconnected when the scope is cleaned up.

useEventual

Returns a state object with an eventual value from a processor. The processor is given a Use callback that adds dependencies, a Become callback alter the current eventual value, and an inner scope to add cleanup tasks to.

useInterval

Sets an interval that runs the callback function every `delay` seconds. If `delay` is `undefined`, the interval is cleared. If the delay changes, the the interval is cleared. If the delay changes, the interval is reset.

useMotion

Returns a state object following a Ripple Motion along with the Motion itself.

useMouse

Returns a state object with the mouse position. Updates when the mouse position changes.

usePrevious

Returns a state object with the previous value of an observable state object. Initially outputs `nil`.

usePx

Returns a state object with the current `px` unit based on the current viewport size.

useSpring

Applies spring animations to the given value, and updates the goal with the latest value on every re-render. Returns a state object with the motor's value. Not to be confused with Fusion's own Spring objects.

useTagged

Returns a state object with every instance of a given tag. Updates when new instances get tagged or old instances get untagged.

useThread

Spawns a new thread that is cancelled once the scope is cleaned up.

useTimer

Creates a timer that can be used to track a value over time.

useViewport

Returns the current viewport size. Updates when the current camera changes or when the viewport size is changed.