1.0.1 ā€¢ Published 1 year ago

leastore v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

LEASTORE

šŸ’š This library was built with TypeScript to handle states in React applications.

It is based on a simplified version of the Zustand core. Compatible with React +18.

npm i leastore

In order to use the library, a store must be declared.

import { useStoreCreator } from "leastore"

export const useStore = useStoreCreator<SLICE_TYPE>((...state) => {
    return {
        ...testSlice(...state)
    }
})

Then it is necessary to declare at least one slice to compose the state.

import { SliceCreator } from "leastore";

export const testSlice: SliceCreator<SLICE_TYPE> = (setState, getState) => {
    return {
        testState: {
            name: "name",
            setName: () => {
                setState((state) => {
                    return {
                        testState: { ...state.testState, name: "new name" }
                    }
                })
            }
        }
    }
}

To use the state we simply need to import the constant declared when we created the store and pass in a selector.

const test = useStore((state) => { return state.testState })

console.log('we access the state slice declared as testState', test)
1.0.1

1 year ago

1.0.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago