
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
redux-request-state
Advanced tools
Redux utilities to deal with HTTP request states (loading, succeeded, failed).
Redux utilities to deal with HTTP request states (loading, succeeded, failed).
Install with npm:
npm install redux-request-state
In a big application, you may end up writing lots of reducers to deal with the three states of a
HTTP request - loading, succeeded and failed.
They will probably all look similar with the following:
import { createStore, combineReducers } from "redux";
// reducer, probably repeated quite a lot in a big application
export function accounts ( state = {}, action ) {
switch ( action.type ) {
case BEGIN_ACCOUNTS_REQUEST:
return Object.assign( {}, state, {
loading: true
});
case ACCOUNTS_REQUEST_SUCCESS:
return Object.assign( {}, state, {
loading: false,
data: action.payload
});
case ACCOUNTS_REQUEST_FAILURE:
return Object.assign( {}, state, {
loading: false,
error: action.payload
});
default:
return state;
}
}
const store = createStore( combineReducers({ accounts }) );
The intention of redux-request-state is to help you get rid of such common reducer, so the above becomes as simple as invoking a factory function:
import { createStore, combineReducers } from "redux";
import { createRequestReducer, createRequestSelectors } from "redux-request-state";
const store = createStore( combineReducers({
accounts: createRequestReducer({
begin: BEGIN_ACCOUNTS_REQUEST,
success: ACCOUNTS_REQUEST_SUCCESS,
failure: ACCOUNTS_REQUEST_FAILURE
})
}));
createRequestReducer( actions )Creates a reducer based on the action names given. Returns the reducer function.
Parameters:
actions: object
begin: Action type that begins the request. Sets the request state to loading.success: Action type that signals a request as succeeded. Sets the request state to not loading,
and saves the payload as the data key of the state.failure: Action type that signals a request as failed. Sets the request state to not loading,
and saves the payload as the error key of the state.createRequestSelectors( baseStateSelector, selectorNames )DEPRECATED
This function is too verbose and doesn't blend well with ES6 modules. It may be removed in the near future.
Creates selector functions to query the state as stored by a reducer created with createRequestReducer.
The returned object contains functions named after selectorNames, and they will query the
corresponding piece of state.
Parameters:
baseStateSelector: functionselectorNames: object
isLoading: name of the selector to query the loading stategetData: name of the selector to query the request resultgetError: name of the selector to query the request errorselectorsIt's an object which contains the following selector functions:
isLoading: queries the loading stategetData: queries the request resultgetError: queries the request errorThey all work by returning the corresponding key in the given state object.
If given a function, it will be used to select the base state where the reducer data lies.
These selectors are available also from redux-request-state/selectors.
import { getData } from "redux-request-state/selectors";
const data = getData( state.accounts );
// Same as above
const data = getData( state => state.accounts )( state );
// Function composition!
const accountsNumber = compose( state => state.accounts, getData, accounts => accounts.length );
// Perhaps you like reselect? https://github.com/reactjs/reselect
const baseAccountsSelector = state => state.accounts;
const listAccounts = createSelector( baseAccountsSelector, getData );
const accountsNumber = createSelector( listAccounts, accounts => accounts.length );
MIT
FAQs
Redux utilities to deal with HTTP request states (loading, succeeded, failed).
We found that redux-request-state 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.