0.1.7 • Published 2 years ago

redux-store-subscribe v0.1.7

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

Redux Store Subscribe Middleware

Using the Redux Store Subscribe Middleware, we can subscribes to value changes in the store.

How to install?

npm install --save redux-store-subscribe

How to use?

Source Code

store.js

import { configureStore } from "@reduxjs/toolkit";
import { storeSubScribeMiddleWare } from "redux-store-subscribe";
import { exampleReducer } from "./slice";

export const store = configureStore({
  reducer: {
    exampleReducer,
  },
  middleware: [storeSubScribeMiddleWare()],
});

AnyWhere.js

import { useEffect } from "react";
import { subScribeToStore, unSubScribeFromStore } from "redux-store-subscribe";

useEffect(() => {
  const id1 = subScribeToStore(
    "exampleReducer.count1",
    ({ prevValue, nextValue }) => {
      alert(`count1 changed from ${prevValue} to ${nextValue}`);
    }
  );

  const id2 = subScribeToStore(
    "exampleReducer.count2",
    ({ prevValue, nextValue }) => {
      alert(`count2 changed from ${prevValue} to ${nextValue}`);
    }
  );

  return () => {
    unSubScribeFromStore(id1);
    unSubScribeFromStore(id2);
  };
}, []);

How to use with TypeScript?

...

Roadmap

  • Providing More Examples
  • Providing TypeScript Examples
  • Writing Tests
0.1.7

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.0.1

2 years ago