React

Real-World Example

A simple counter with reactive state that increments on each click.

import { defineStore, useStore } from '@vegajs/vortex';

const counterStore = defineStore(({ reactive, computed }) => {
    const count = reactive(0);
    const increment = () => count.set(prev => prev + 1);

    return { count, increment };
});

export const A = () => {
    const { count, increment } = useStore(counterStore);

    return (
        <div>
            <p>count: {count}</p>
            <button onClick={increment}>Increment</button>
        </div>
    );
};

Result

render: 0

count: 0