@zeruxjs/hooks
v0.0.3
Published
Request-scoped React-style hooks, context, and safe ZeruxJS path registry
Downloads
235
Readme
@zeruxjs/hooks
Server-side scoped hooks and path aliases for ZeruxJS. ESM imports. Uses Node AsyncLocalStorage for request isolation.
import { runWithRequestHooks, createContext, setContext, useContext, runHooks, useState, useEffect, disposeHooks } from '@zeruxjs/hooks';
const locale = createContext('en');
runWithRequestHooks(() => {
setContext(locale, 'fr');
const component = () => { const [value, set] = useState(0); return { value, set, locale: useContext(locale) }; };
const state = runHooks(component);
state.set(previous => previous + 1);
console.log(runHooks(component).value); // 1
disposeHooks(component);
});Hooks are synchronous-render only and intentionally do not trigger rendering themselves; applications must schedule rerenders. Calling a different number/order of hooks on subsequent renders throws. Effects clean up on dependency changes and disposal. For nested request contexts, use withContext.
createPathRegistry({ directory }) manages aliases with validated names and atomic private writes. The legacy registerPath, resolvePath, getAllPaths, unregisterPath wrappers use the current working directory at invocation time. Multi-process registry writes require caller-side serialization; atomic renames prevent partial files but do not prevent concurrent lost updates.
Release 0.0.2
Prepared to validate npm trusted publishing through GitHub Actions.
Release 0.0.3
Synchronized ecosystem release, including Zuixs CSS-entry support and documentation updates. Existing placeholder packages retain their documented limitations.
