0.0.2 • Published 11 months ago

@infinityfx/gs v0.0.2

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
11 months ago

GS

NPM package NPM bundle size Last commit NPM weekly downloads NPM downloads

React persistable global store.

Usage

Creating stores

import { createGlobalStore } from '@infinityfx/gs';

export const useNotesStore = createGlobalStore({
    initial: ['My first note'],
    // persist the data to local storage (is false by default)
    persist: true
});

export const useFruitsStore = createGlobalStore({
    initial: {
        apple: 0,
        banana: 0,
        strawberry: 0,
        tomato: 0
    },
    // only persist a subset of data
    persist: ['apple', 'banana', 'strawberry'],
    // specify a custom key to store data under
    key: 'fruits-data'
});

Using and mutating data

import { useCounterStore } from './stores';

export default function MyComponent() {
    const [data, mutate] = useCounterStore();

    // You can update state by mutating the data passed inside the mutate callback
    return <button onClick={() => mutate(data => data.counter++)}>
        {data.counter}
    </button>;
}
0.0.2

11 months ago

0.0.1

12 months ago

0.0.0

12 months ago