Example
GitHub Example
StoreContext vs. Redux
Advantages
Disadvanteges
- All components are rerendered when any component uses the store (in the same scope of context).
Functions
store = ()
Get all lists of the models.
get = (model: string, predicate: func)
Get items from store which are consistent with the predicate function.
add = (model: string, item: JSonObject)
Add item into store into the set which model name is given.
remove = (model: string, predicate: func)
Remove item(s) from store which are consistent with the predicate function.
clear = (model: string default null)
Clear a set which model name is given. If model is null, then clears all store.
Usage
Main.js
import { StoreProvider } from "store-contet";
const Main = (props) => {
//...
return
//...
<StoreProvider>
<OtherElements />
</StoreProvider>
//...
OtherElements.js
import { useStore } from "store-contet";
//...
const OtherElements = (props) => {
//...
const { get, add, remove, clear } = useStore();
//... Do Work