@illostack/react-store and @illostack/store are lightweight state management libraries for JavaScript and TypeScript applications. @illostack/react-store is specifically designed for React, while @illostack/store is a framework-agnostic version of the same core functionality.
- State Management: Easily manage global state across your application.
- React Support:
@illostack/react-storeprovides optimized hooks for use in React components. - Framework-Agnostic:
@illostack/storeworks with any JavaScript framework. - Easy to Use: Simple API with hooks to manage and subscribe to state changes.
- Efficient: Minimal re-renders and performance optimizations.
To install the React-specific package:
npm install @illostack/react-storeTo install the core package:
npm install @illostack/store-
Create a Store:
First, create a store using
createStore:import { createStore } from "@illostack/react-store"; const store = createStore({ count: 0 });
-
Use
useStoreHook:Use the
useStorehook to access state in a React component:import { useStore } from "@illostack/react-store"; const Counter = () => { const count = useStore(store, state => state.count); return <div>{count}</div>; };
-
Use
useStoreEffectHook:Use
useStoreEffectto trigger side effects when the state changes:import { useStoreEffect } from "@illostack/react-store"; const Counter = () => { useStoreEffect(store, state => state.count, (state, prevState) => { console.log("State changed:", state.count); }); // No re-renders ... };
You can use @illostack/store in any JavaScript framework to manage state without the React hooks. Here's an example of creating a store:
import { createStore } from "@illostack/store";
const store = createStore({
count: 0
});For more detailed usage, advanced guides, and API reference, check the full documentation:
We welcome contributions! To contribute, please follow these steps:
- Fork the repository.
- Clone your fork locally.
- Create a new branch.
- Make your changes.
- Commit your changes.
- Push to your fork.
- Open a pull request.
Please ensure that your code follows the existing style and includes tests where applicable.
This project is licensed under the MIT License. See the LICENSE file for more details.
