hook-style-data
v0.2.0
Published
Tiny hook-style state manager for plain JavaScript (useState, useEffect, useRef, createStore) - no React required.
Maintainers
Readme
hook-style-data
Tiny hook-style state manager for plain JavaScript.
This package provides a minimal hook runtime for use in non-React environments. It supports:
- useState(initial) — stateful value with a setter that triggers a re-render of that component's function.
- useEffect(cb, deps) — side-effect that runs after render and on dependency changes; returns optional cleanup.
- useRef(initial) — mutable ref object: { current }
- createComponent(fn) — create a component runner with hooks persistence across renders.
- createStore(initial) — tiny pub/sub store with get/set/subscribe and a
useStore()helper.
Files are intentionally split so each unit is small and testable.
Usage example (see test/test.js for a runnable demo):
const { createComponent, createStore } = require('hook-style-data');
const store = createStore({ count: 0 });
const App = createComponent(() => {
const [local, setLocal] = useState(0);
useEffect(() => {
console.log('effect: local, store', local, store.get().count);
return () => console.log('cleanup');
}, [local, store.get().count]);
return { renderOutput: `local=${local}` };
});
App.render();
To run the demo locally:
- node test/test.js
License: MIT
