A boilerplate free simple state management library
MIT License
A boilerplate free state management library for your React, Next.js, Preact and SolidJS applications. Check out the documentation for quick start.
For the core library:
npm install @poly-state/core
For React and Next.js:
npm install @poly-state/core @poly-state/react
For Preact:
npm install @poly-state/core @poly-state/preact
For more installation details, see the instructions.
Documentation for poly-state is located at https://poly-state.github.io.
import { createStore } from '@poly-state/core';
import { useStore } from '@poly-state/react'; // React & Next.js only
// import { useStore } from '@poly-state/preact'; // Preact only
// Create your own store
const counterStore = createStore({ count: 0 });
const useCounterStore = () => useStore(counterStore);
// Your React / Next.js / Preact component
export const MyCounter = () => {
const { count } = useCounterStore();
return (
<div>
<h1>{count}</h1>
<button onClick={() => counterStore.setCount(prev => prev - 1)}>Decrement</button>
<button onClick={() => counterStore.setCount(prev => prev + 1)}>Increment</button>
</div>
);
};
npm install @poly-state/react
yarn add @poly-state/react
npm install @poly-state/preact
yarn add @poly-state/preact
It is also possible to use this library in other frontend frameworks/libraries, we plan on adding support for Svelte, Vue, Angular in the near future.
Issues and pull requests of all sorts are welcome!
More Documentation and Advanced usage examples can be found in the documentation.
This project is licensed under the MIT License.