0.1.9 • Published 9 months ago

respondx v0.1.9

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

storax

1. Create Store

use createStore to create a store globally accessded

const { dispatch, useConnector } = createStore({ count: 0 });

2. Read Operation

use useConnector to access properties in that store

const count = useConnector((state) => state.count);

3. Write Operation

use dispatch to update properties

dispatch((state) => (state.count = state.count + 1));

Just keep in mind

both write and read operation interfaces only accept function. all you need to do is to play around with the 1st arg that the func passes to you.

useConnector((beAnyNameOfTheArg) => beAnyNameOfTheArg.prop1.subProp2);

dispath((beAnyNameOfTheArg) => {
  beAnyNameOfTheArg.prop1 += 10;
  beAnyNameOfTheArg.prop2 += "any thing";
});

4. Full example

import { createStore } from "respondx";

const { dispatch, useConnector } = createStore({ count: 0 });

function App() {
  const count = useConnector((state) => state.count);
  return (
    <div>
      {count}

      <button
        onClick={() => {
          dispatch((state) => (state.count = state.count + 1));
        }}
      >
        click
      </button>
    </div>
  );
}

export default App;
0.1.8

9 months ago

0.1.7

9 months ago

0.1.9

9 months ago

0.1.6

9 months 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

1.0.1

2 years ago

1.0.0

2 years ago