2.2.1 • Published 5 years ago
kedge v2.2.1
Kedge
Easy to use global state hook for React.

Installation
npm install kedgeUsage
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);
}API
const store = createStore(initialState, optionalName)Creates a
Storewith initial value. Optionally, it accepts a store name that is used in React Dev Toolsconst state = useStore(store)Returns current state from the
Storeand subscribes the component to it. If theStorechanges state the component will re-render.Store.set(newState)Sets
Storestate and re-renders all components that use it.Store.reset()Sets
Storeto initial value and re-renders all components that use it.