what-core
v0.8.4
Published
What Framework - The closest framework to vanilla JS
Maintainers
Readme
what-core
The reactive engine behind What Framework. Provides signals, fine-grained reactivity, components, hooks, and DOM rendering -- all without a virtual DOM diffing step.
Most users should install what-framework instead. what-core is the internal engine consumed by other What packages.
Install
npm install what-coreReactive Primitives
import { signal, computed, effect, batch, untrack } from 'what-core';
const count = signal(0);
// Read
count(); // 0
// Write
count.set(5);
count.set(c => c + 1);
// Derived value
const doubled = computed(() => count() * 2);
// Side effects
effect(() => {
console.log('Count:', count());
});
// Batch updates (effects run once at the end)
batch(() => {
a.set(1);
b.set(2);
});
// Read without subscribing
untrack(() => someSignal());
count.peek();Hooks
React-compatible hooks backed by signals internally.
import {
useState, useEffect, useMemo, useCallback,
useRef, useReducer, useContext, createContext,
onMount, onCleanup,
} from 'what-core';
const [count, setCount] = useState(0);
useEffect(() => {
const id = setInterval(tick, 1000);
return () => clearInterval(id);
}, []);Components
import { mount, signal } from 'what-core';
function Counter() {
const count = signal(0);
return (
<button onClick={() => count.set(c => c + 1)}>{count()}</button>
);
}
mount(<Counter />, '#app');Additional Modules
| Export path | Contents |
|---|---|
| what-core | Signals, hooks, components, store, forms, data fetching, animation, a11y, skeleton loaders |
| what-core/render | Fine-grained rendering primitives (template, insert, spread, delegateEvents) |
| what-core/jsx-runtime | JSX automatic runtime |
| what-core/testing | Test utilities |
API Overview
Reactivity -- signal, computed, effect, batch, untrack, flushSync, createRoot
Rendering -- Fragment, html, mount, template, insert, spread, delegateEvents
Hooks -- useState, useSignal, useComputed, useEffect, useMemo, useCallback, useRef, useContext, useReducer, createContext, onMount, onCleanup, createResource
Components -- memo, lazy, Suspense, ErrorBoundary, Show, For, Switch, Match, Island, Portal
Store -- createStore, derived, atom
Data Fetching -- useSWR, useQuery, useInfiniteQuery, invalidateQueries, prefetchQuery
Forms -- useForm, useField, rules, zodResolver, Input, Select, Checkbox, ErrorMessage
Animation -- spring, tween, easings, useGesture, useTransition
Accessibility -- useFocusTrap, FocusTrap, announce, SkipLink, useRovingTabIndex, VisuallyHidden, useId
Scheduler -- scheduleRead, scheduleWrite, measure, mutate, onResize, onIntersect
Head -- Head, clearHead
Links
License
MIT
