Easy to use global state hook for React.
npm install kedge
import { createStore, useStore } from 'kedge';
const priceStore = createStore();
function PriceComponent() {
const price = useStore(priceStore);
useEffect(fetchPrice, []);
return (
<div>
Price: { price }
</div>
);
}
function fetchPrice() {
priceStore.set(73);
}
Creates a Store
with initial value. Optionally, it accepts a store name that is used in React Dev Tools
Returns current state from the Store
and subscribes the component to it. If the Store
changes state the component will re-render.
Sets Store
state and re-renders all components that use it.
Sets Store
to initial value and re-renders all components that use it.