preact-sigma is a typed state-model builder for Preact and TypeScript. It keeps top-level public state reactive, derived reads local to the model, writes explicit through actions, and side effects owned by explicit setup.
npm install preact-sigma @preact/signals immer preactimport { SigmaType } from "preact-sigma";
const Counter = new SigmaType<{ count: number }>("Counter")
.defaultState({
count: 0,
})
.computed({
doubled() {
return this.count * 2;
},
})
.actions({
increment() {
this.count += 1;
},
});
const counter = new Counter();
counter.increment();
console.log(counter.count); // 1
console.log(counter.doubled); // 2- Concepts, lifecycle, invariants, and API selection live in
docs/context.md. - Persistence-specific guidance lives in
docs/persist.md. - Runnable usage patterns live in
examples/, starting withexamples/basic-counter.tsandexamples/command-palette.tsx. - Exact exported signatures live in
dist/*.d.mtsafterpnpm build.