reactive-state-handler
A Cross Framework Javascript State Management Library using rxjs
Install Peer Dependency ( in case not installed already )
npm i rxjs
Steps to Install
npm i reactive - state - handler
Example Usage
- Create a new file (suppose AppStateHandler.js) and initialize your initial state and default export Singleton Class.
; ;
- Import in any file and then you can use any of it's methods & properties listed below
// Used for listening to state changesAppStateHandler.subscriber$.subscribe; // Used for setting values in the stateAppStateHandler.setStatevalues; // Returns current state; // Used to reset state back to initial stateAppStateHandler.resetState;
- Usage with React
Create a custom react hook
; { return ;}
Lastly, just use this in your functional component
// Returns only values passed in the filterKeys, use this to reduce unnecessary re renders if other state values changes.const keyName1 keyName2 removeListener addListener = ;// Returns current stateconst state removeListener addListener = ;