Hideaway Redux Middleware
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
Hideaway is a Redux middleware (v1.0.0) that streamlines API calls and state management by reducing boilerplate for reducers, selectors, and thunks. It provides a state manager for handling loading/error/data states, supports nested paths, and includes an apiPreReducer hook. Compared to redux-toolkit, it offers a more opinionated approach focused on async actions and automatic state shape generation. The package is ESM-only, ships TypeScript types, and requires Redux 4. Recent releases (0.2.x-0.3.x) introduced breaking changes to the API (e.g., renamed methods, new signatures for onError, generateSelector→getValue).
Common errors
error Uncaught ReferenceError: require is not defined ↓
cause Trying to use require() with an ESM-only package.
fix
Change to import statement or ensure your environment supports ESM.
error TypeError: hideaway is not a function ↓
cause Importing hideaway incorrectly (e.g., importing as named export instead of default).
fix
Use import hideaway from 'hideaway' (default import).
error Module not found: Can't resolve 'hideaway' ↓
cause Package not installed or wrong version.
fix
Run npm install hideaway and check package.json.
error Error: Redux 'stateManager' reducer must not return undefined ↓
cause stateManager is not applied correctly, or initial state is undefined.
fix
Ensure stateManager wraps your root reducer and initial state is defined.
Warnings
breaking generateSelector renamed to getValue in v0.2.0. Old import will throw an error. ↓
fix Replace all imports of generateSelector with getValue.
breaking onError signature changed in v0.2.3: now receives (action, response, getState, dispatch, onErrorApi, withExtraArgument). Old signature (action, error) will break. ↓
fix Update onError callback to handle the new parameters.
deprecated The isNested option for stateManager was replaced by hasNested in v0.3.4. isNested may be removed in future versions. ↓
fix Use hasNested=true instead of isNested=true in state manager usage.
breaking In v0.2.2, the middleware now adds a 'type' property to the action object root, which may conflict with existing code that expects action.type to be the only type field. ↓
fix Ensure any custom middleware or reducers that mutate action.type are compatible.
gotcha hideaway requires Redux v4 as a peer dependency. Using older Redux versions may cause runtime errors. ↓
fix Install redux@^4 or higher.
gotcha The default export hideaway() expects no arguments; passing arguments will throw an error. ↓
fix Call hideaway as a function with zero arguments in applyMiddleware.
Install
npm install hideaway yarn add hideaway pnpm add hideaway Imports
- hideaway wrong
const hideaway = require('hideaway')correctimport hideaway from 'hideaway' - stateManager wrong
import { StateManager } from 'hideaway' (case-sensitivity)correctimport { stateManager } from 'hideaway' - getValue wrong
import { generateSelector } from 'hideaway' (renamed in v0.2.0)correctimport { getValue } from 'hideaway'
Quickstart
import { createStore, applyMiddleware } from 'redux';
import hideaway from 'hideaway';
import { stateManager } from 'hideaway';
const initialState = {};
const rootReducer = (state = initialState, action) => state;
const store = createStore(
stateManager(rootReducer),
applyMiddleware(hideaway)
);
// To use with thunk-like API calls:
store.dispatch({
type: 'FETCH_DATA',
payload: { url: '/api/data' },
});