Registry / web-framework / redux-async-initial-state

redux-async-initial-state

JSON →
library0.3.0jsnpmunverified

A Redux middleware for loading initial application state asynchronously from sources like HTTP APIs or React Native's AsyncStorage. Current version 0.3.1, maintained with intermittent updates. Provides `outerReducer`, `innerReducer`, and `middleware` to handle async state loading and loading/error UI state. Differentiates from manual promise handling by offering a structured middleware approach that integrates with Redux's store creation. Compatible with Redux 4.0.0+.

npm install redux-async-initial-state
INSTALL
IMPORT
SIG · REDUX-ASYNC-INITIA
R
redux-async-initial-state
web-frameworkjavascriptv0.3.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

outerReducer
✓ import { outerReducer } from 'redux-async-initial-state'
✗ import outerReducer from 'redux-async-initial-state'
Named export, not default. Must use destructured import.
innerReducer
✓ import { innerReducer } from 'redux-async-initial-state'
✗ import { innerReducer } from 'redux-async-initial-state/inners'
Named export, no subpath. Optional; only needed if tracking loading state.
middleware
✓ import { middleware } from 'redux-async-initial-state'
✗ const middleware = require('redux-async-initial-state').middleware
Named export, available as ESM or CJS. CJS require works but ESM is preferred.
LOADING
✓ import { LOADING } from 'redux-async-initial-state'
Action type constant, named export. Used internally; rarely needed by consumers.

Sets up Redux store with async initial state loading via HTTP fetch.

import { createStore, applyMiddleware, combineReducers, compose } from 'redux'; import { outerReducer, innerReducer, middleware } from 'redux-async-initial-state'; const reducer = outerReducer(combineReducers({ // ... your reducers asyncInitialState: innerReducer, })); const loadStore = () => { return new Promise(resolve => { fetch('/api/initial-state') .then(response => response.json()) .then(resolve); }); }; const store = createStore( reducer, compose(applyMiddleware(middleware(loadStore))) );
Debug
Known issues
breakingUsing this middleware with Redux 4.0.0+ requires version 0.3.0+. Older versions may cause errors.
fix
Update to version >=0.3.0
affects: <0.3.0
gotchaThe `middleware` function must be called with a `loadStore` argument that returns a Promise. Omitting it or using a non-Promise will cause runtime error.
fix
Ensure loadStore returns a Promise (e.g., using async/await or explicit new Promise).
affects: >=0.1.0
gotchaThe `outerReducer` must wrap your combined reducer. Failure to do so will break state replacement when async state loads.
fix
Always use: const rootReducer = outerReducer(combineReducers({...}));
affects: >=0.1.0
deprecatedImporting via `require('redux-async-initial-state')` is still supported but ESM imports are preferred for tree-shaking.
fix
Switch to import { ... } from 'redux-async-initial-state'
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: middleware is not a function
Calling `middleware` as a function without argument or using it directly in applyMiddleware without invoking it first.
fix
Use applyMiddleware(middleware(loadStore))
Uncaught Error: Expected the nextReducer to be a function
The outerReducer received something that is not a reducer (e.g., plain object or undefined).
fix
Ensure outerReducer wraps a valid reducer, e.g., outerReducer(combineReducers({...}))
Action 'REDUX_ASYNC_INITIAL_STATE' not recognized by reducer
Missing `outerReducer` wrapper, so the store's reducer does not handle the async state replacement action.
fix
Wrap your combined reducer with outerReducer.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
redux-async-initial-state — npm install redux-async-initial-state · libregistry