0.2.0 • Published 2 years ago

store-context v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Example

GitHub Example

StoreContext vs. Redux

Advantages

  • Simple than Redux.

  • Easy to use.

  • More than one store in one page.

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
0.2.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago