Search code examples
reactjsreduxstatestore

Can you create a react redux store interceptor to watch a property?


Let's say i have a property in the store called state.items.byId each time this is updated (various parts of the application) i want to intercept the value before i'ts updated and run a function to update some properties on it before it's updated.

I don't know the terminology and i'm quite new to redux, but if someone could point me in the right direction that would be great!

I have searched and found redux-watch but i'm not 100% sure if this is the right approach


Solution

  • below shows the data flow in a redux application. View dispatches an action, the action object is a blue-print telling the reducer what changes it needs to make to the store state. Any change in the redux store state needs to pass through this cycle.

    redux-watch provides you a subscription based mechanism notifying you after a property is changed. If you want to intercept a property before its changed you can write a custom middleware and handle any side-effects inside it.