aohua / redux-state-sync

A lightweight middleware to sync your redux state across browser tabs
MIT License
233 stars 29 forks source link

How to stop/disable/pause syncing? #156

Closed EvgenyOrekhov closed 1 year ago

EvgenyOrekhov commented 1 year ago

I need the ability to disable/enable syncing depending on a prop in Redux state. Is it possible?

EvgenyOrekhov commented 1 year ago

I ended up creating a middleware wrapper for that:

const conditionalStateSyncMiddleware: Middleware<unknown, RootState> =
  store => next => action =>
    store.getState().isStateSyncEnabled
      ? stateSyncMiddleware(store)(next)(action)
      : next(action);