zustore-vignesh
v1.0.4
Published
A minimal Zustand-like state management library with plugin support, created by Vignesh Pandian.
Downloads
15
Readme
zustore
A minimal Zustand-like state management library with plugin support, created by Vignesh Pandian.
Features
- Create and manage global store
- Plugin support (logger, persist, immer)
- React bindings
Installation
npm install @vignesh/zustoreUsage
Basic Example in React
import { createStore } from '@vignesh/zustore';
import { createHook } from '@vignesh/zustore/react';
// Create a global store with initial state
const store = createStore({ count: 0 });
// Create a hook to access the store
const useStore = createHook(store);
// Simple component to display and increment count
function Counter() {
const count = useStore(state => state.count);
return (
<div>
<p>Count: {count}</p>
</div>
);
}
export default Counter;
Basic Example in React Native
import React from 'react';
import { Text, View, Button } from 'react-native';
import { createStore } from '@vignesh/zustore';
import { createHook } from '@vignesh/zustore/react-native';
// Create a global store with initial state
const store = createStore({ count: 0 });
// Create a hook to access the store
const useStore = createHook(store);
// Simple component to display and increment count
function Counter() {
const count = useStore(state => state.count);
return (
<View>
<Text>Count: {count}</Text>
<Button title="Increment" onPress={() => store.setState({ count: count + 1 })} />
</View>
);
}
export default Counter;
