@poly-state/react
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

React bindings for Poly state

How to install

npm install @poly-state/react
#or
yarn add @poly-state/react

Example

import { createStore } from '@poly-state/core';
import { createStoreSelector } from '@poly-state/react';

export type CounterStoreType = {
	count: number;
};

export const counterStoreInitialState: CounterStoreType = {
	count: 0,
};

export const counterStore = createStore(counterStoreInitialState);
export const useCounterStoreSelector = createStoreSelector(counterStore);

On Component level

const TestComponent = () => {
	const count = useCounterStoreSelector((state) => state.count);

	const increment = () => {
		counterStore.setCount((prev) => prev + 1);
	};

	return <h1 onClick={increment}>{count}</h1>;
};

Package Sidebar

Install

npm i @poly-state/react

Weekly Downloads

7

Version

4.0.0

License

MIT

Unpacked Size

11.5 kB

Total Files

9

Last publish

Collaborators

  • shahriar-shojib