Installation

npm
yarn
pnpm
npm add vergajs/vortex@latest

Creating your first reactive Store

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 doubleCount = computed(() => count.value * 2);
    const increment = () => count.set(prev => prev + 1);

    return { count, doubleCount, increment };
});

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

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

Result:

render: 0

count: 0