
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
react-usemiddleware
Advanced tools
React >=16.7 hook, allowing to use standard Redux middleware with useReducer
useMiddleware
hookRedux compatible middleware provider for React >=16.7 Hooks
react-useMiddleware allows you to use all existing Redux middlewares with React's new feature called hooks.
It introduces new hook called useMiddleware
, which is a wrapper arounf useReducer
, but allows you to pass a list of middlewares to be used.
$ npm install react-usemiddleware --save
$ yarn add react-usemiddleware
you can use useMiddleware
as a straight replacement for useReducer
, and optionally pass 3rd parameter - an array of middlewares to be applied to a dispatch function.
const [state, dispatch] = useMiddleware(reducer, initialState, middlewares = []);
Takes 3 parameters:
reducer
, same as passed into useReducer
hookinitialState
, same as passed into useReducer
hookmiddlewares
- array of middlewares, eg, [thunk, createLogger, saga]
import React from 'react';
import useMiddleware from 'react-usemiddleware';
import { createLogger } from "redux-logger";
import thunk from "redux-thunk";
const logger = createLogger();
const middlewares = [thunk, logger];
const reducer = (state, action) => {
switch (action.type) {
case "INC":
return state + 1;
case "DEC":
return state - 1;
case "SET":
return action.payload;
default:
return state;
}
};
const App = (props) => {
const [count, dispatch] = useMiddleware(reducer, 0, middlewares);
const thunkAction = dispatch(() => setTimeout(() => dispatch({ type: "SET", payload: 7 })), 1000);
const incCount = () => dispatch({ type: "INC" });
const decCount = () => dispatch({ type: "DEC" });
return (
<div className="App">
<button onClick={decCount}>[-]</button>
<span>{count}</span>
<button onClick={incCount}>[+]</button>
<button onClick={thunkAction}>Async</button>
</div>
);
}
A demo can be found here
FAQs
React >=16.7 hook, allowing to use standard Redux middleware with useReducer
The npm package react-usemiddleware receives a total of 7 weekly downloads. As such, react-usemiddleware popularity was classified as not popular.
We found that react-usemiddleware 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
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.