@scripty/react-store
Version:
This lightweight global react hook store is inspired by the extjs store architecture. Share your stores through your application with only a few lines of code!
20 lines (14 loc) • 510 B
JSX
import { useContext } from 'react';
import { StoreContext, addStore, getStore } from './';
export const useStore = (storeName) => {
let { store, setStore } = useContext(StoreContext);
const mStore = window.globalStorage.config[storeName];
window.globalStorage.setStore = (e) => {
setStore(e)
};
addStore({ name: storeName, store: mStore }, storeName);
let records = getStore(store, storeName);
return {
[storeName]: records.store,
};
};