
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
redux-active
Advanced tools
Redux middleware & reducer to easily manage your users active/idle state
Tiny footprint: ~0.5 kB
This has a peer dependency of redux, which will have to be installed as well.
npm install --save redux-active
redux-active is also published as an UMD build. You can use it via the unpkg CDN:
https://unpkg.com/redux-active@latest/dist/umd/redux-active.min.js
First, you must add the middleware to your redux store.
// store.js
import { createStore, applyMiddleware } from 'redux'
import { createActiveMiddleware } from 'redux-active'
import rootReducer from './rootReducer'
const activeMiddleware = createActiveMiddleware()
const store = createStore(
rootReducer,
applyMiddleware(activeMiddleware)
)
Second, add the reducer to the root of your reducer tree.
// rootReducer.js
import { combineReducers } from 'redux'
import { activeReducer } from 'redux-active'
export default combineReducers({
isActive: activeReducer,
})
With this basic setup, redux-active adds event listeners to the window object to detect your users activity. Based on the events being triggered, the middleware dispatches IS_IDLE and IS_ACTIVE actions, based on which the reducer manages a isActive boolean in your state indicating if the user is active or not.
Imagine a dashboarding application where dashboards viewed on a large screen can be set to a fullscreen mode. Using the isActive flag provided by this module, various controls such as buttons or links could be hidden when the user is inactive whilst in fullscreen mode.
createActiveMiddleware accepts options to fine tune redux-active to your needs:
import { throttle } from 'lodash'
const activeMiddleware = createActiveMiddleware({
idleTimeout: 10000,
stateSelector: state => state.user.isActive,
throttle,
})
Available options are:
eventTargeteventThrottleTimeouteventTypeseventTarget.idleCheckIntervalidleTimeoutstateSelectorisActive boolean when given the state.throttleNote that if you are using additional middleware, custom enhancers or initialize the store with an initial state, the createStore call might look more like this:
import { createStore, compose, applyMiddleware } from 'redux'
import { createActiveMiddleware } from 'redux-active'
import rootReducer from './rootReducer'
const activeMiddleware = createActiveMiddleware()
const store = createStore(
rootReducer,
initialState,
compose(
otherEnhancer,
applyMiddleware(activeMiddleware, otherMiddleware)
)
)
If you can't get this to work, be sure to consult the redux documentation and understand the difference between middleware and enhancers as well as the API of the createStore, compose and applyMiddleware methods.
FAQs
Manages users active & idle state
We found that redux-active demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.