Skip to content

ArtisanPack UI home

Hooks - JS

WordPress-style actions and filters for JavaScript and TypeScript, with a first-class React adapter. Zero runtime dependencies, Module Federation-safe singleton, SSR-safe — the JS counterpart to artisanpack-ui/hooks for PHP.

v1.0.0

MIT License

★ 0

npm install @artisanpack-ui/hooks-js
terminal
$ npm install @artisanpack-ui/hooks-js
✓ added 1 package · 0 dependencies

addAction('order.placed', (order) => sendReceipt(order));
doAction('order.placed', order);
applyFilters('price.display', '49.00', 'USD'); // "USD 49.00"

What it does

Extension points for your frontend

Register callbacks on named hooks and thread values through filters anywhere in your JS app — with the same naming convention, priorities and deprecation semantics as the PHP twin.

Actions & filters

addAction, doAction, addFilter, applyFilters and their remove* and has* counterparts.

Zero dependencies

A framework-agnostic core with no runtime dependencies; the React adapter is an optional subpath.

Priority ordering

Lower priorities run first, FIFO within a bucket. Callbacks added mid-dispatch defer to the next one.

Deprecation aliases

deprecateHook renames a hook without breaking subscribers. Chains collapse, cycles throw.

Module Federation-safe

A shared globalThis singleton means duplicate copies still find each other's callbacks.

SSR-safe

No window access on import, and React hooks render from a safe server snapshot.

Install and start hooking

Import from the core entry point for framework-agnostic use, or from /react for the hooks and <HookSlot>.

Install

npm install @artisanpack-ui/hooks-js

PHP twin (optional)

composer require artisanpack-ui/hooks

Reactivity, first class

Every hook is backed by useSyncExternalStore on a per-hook version counter, so components re-render on registry mutations. Safe under StrictMode and SSR.

useFilter

Read a filtered value and re-render whenever the registry mutates.

useAction

Fire an action from an effect, with deep-compared arguments.

useHookedChildren

Thread ReactNode children through a filter before rendering them.

HookSlot

The component form of the filter-a-value pattern, for markup-level extension points.

What you need

Requirement Detail
Runtime Any modern browser or Node runtime (Node 20+ for local development)
TypeScript Optional — ships its own types (ESM, CJS and .d.ts)
React 18 or 19, optional peer — only for the /react subpath
Shares hook names with the PHP twin, including the ecosystem-wide ap.google.scopes and ap.icons.registerIconSets filters.

Make your frontend extensible with Hooks JS

Actions and filters for JS and TS in one install, with a React adapter that re-renders for you. Free and open source under the MIT license.