@coaction/react
v1.5.0
Published
A Coaction integration tool for React
Readme
@coaction/react
A Coaction integration tool for React
Installation
You can install it via npm, yarn or pnpm.
npm install coaction @coaction/reactCompatibility
@coaction/react currently supports React 17, 18, and 19.
The package intentionally uses use-sync-external-store/shim internally so the
same published build can work across those React versions. Removing the shim
would require dropping React 17 support in a future major release.
Usage
import { create } from '@coaction/react';
const useStore = create((set) => ({
count: 0,
increment: () => set((state) => state.count++)
}));
const CounterComponent = () => {
const store = useStore();
return (
<div>
<p>Count: {store.count}</p>
<button onClick={store.increment}>Increment</button>
</div>
);
};For selector-heavy components, autoSelector returns a cached selector map
instead of values. Hook calls stay explicit:
const selectors = useStore.auto();
const CounterComponent = () => {
const count = useStore(selectors.count);
const increment = useStore(selectors.increment);
return <button onClick={increment}>Count: {count}</button>;
};useStore({ autoSelector: true }) is kept as an alias for useStore.auto().
autoSelector is generated from the store shape known during initialization.
If your application adds new keys at runtime, prefer explicit selectors such as
useStore((state) => state.dynamic[key]) for those paths instead of expecting
the cached selector map to grow dynamically.
Documentation
You can find the documentation here.
