Quick Start
Let’s jump into using QuantaJS with a simple counter example.
Example: Counter Store
Here’s how to create a reactive counter using createStore
:
import { createStore } from "quantajs";
const counter = createStore({
state: { count: 0 },
actions: {
increment() {
this.count++;
},
decrement() {
this.count--;
},
},
});
// Access state
console.log(counter.count); // 0
// Update state
counter.increment();
console.log(counter.count); // 1
counter.decrement();
console.log(counter.count); // 0
What’s Happening?
createStore
creates a reactive store with astate
object andactions
.- The
state
is made reactive, so changes trigger updates automatically. - Actions like
increment
anddecrement
modify the state directly usingthis
.