{"id":18724,"library":"redux-async-initial-state","title":"Redux Async Initial State","description":"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+.","status":"maintenance","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/KELiON/redux-async-initial-state","tags":["javascript","redux","initial","state","async"],"install":[{"cmd":"npm install redux-async-initial-state","lang":"bash","label":"npm"},{"cmd":"yarn add redux-async-initial-state","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-async-initial-state","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export, not default. Must use destructured import.","wrong":"import outerReducer from 'redux-async-initial-state'","symbol":"outerReducer","correct":"import { outerReducer } from 'redux-async-initial-state'"},{"note":"Named export, no subpath. Optional; only needed if tracking loading state.","wrong":"import { innerReducer } from 'redux-async-initial-state/inners'","symbol":"innerReducer","correct":"import { innerReducer } from 'redux-async-initial-state'"},{"note":"Named export, available as ESM or CJS. CJS require works but ESM is preferred.","wrong":"const middleware = require('redux-async-initial-state').middleware","symbol":"middleware","correct":"import { middleware } from 'redux-async-initial-state'"},{"note":"Action type constant, named export. Used internally; rarely needed by consumers.","wrong":"","symbol":"LOADING","correct":"import { LOADING } from 'redux-async-initial-state'"}],"quickstart":{"code":"import { createStore, applyMiddleware, combineReducers, compose } from 'redux';\nimport { outerReducer, innerReducer, middleware } from 'redux-async-initial-state';\n\nconst reducer = outerReducer(combineReducers({\n  // ... your reducers\n  asyncInitialState: innerReducer,\n}));\n\nconst loadStore = () => {\n  return new Promise(resolve => {\n    fetch('/api/initial-state')\n      .then(response => response.json())\n      .then(resolve);\n  });\n};\n\nconst store = createStore(\n  reducer,\n  compose(applyMiddleware(middleware(loadStore)))\n);","lang":"javascript","description":"Sets up Redux store with async initial state loading via HTTP fetch."},"warnings":[{"fix":"Update to version >=0.3.0","message":"Using this middleware with Redux 4.0.0+ requires version 0.3.0+. Older versions may cause errors.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Ensure loadStore returns a Promise (e.g., using async/await or explicit new Promise).","message":"The `middleware` function must be called with a `loadStore` argument that returns a Promise. Omitting it or using a non-Promise will cause runtime error.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always use: const rootReducer = outerReducer(combineReducers({...}));","message":"The `outerReducer` must wrap your combined reducer. Failure to do so will break state replacement when async state loads.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Switch to import { ... } from 'redux-async-initial-state'","message":"Importing via `require('redux-async-initial-state')` is still supported but ESM imports are preferred for tree-shaking.","severity":"deprecated","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use applyMiddleware(middleware(loadStore))","cause":"Calling `middleware` as a function without argument or using it directly in applyMiddleware without invoking it first.","error":"TypeError: middleware is not a function"},{"fix":"Ensure outerReducer wraps a valid reducer, e.g., outerReducer(combineReducers({...}))","cause":"The outerReducer received something that is not a reducer (e.g., plain object or undefined).","error":"Uncaught Error: Expected the nextReducer to be a function"},{"fix":"Wrap your combined reducer with outerReducer.","cause":"Missing `outerReducer` wrapper, so the store's reducer does not handle the async state replacement action.","error":"Action 'REDUX_ASYNC_INITIAL_STATE' not recognized by reducer"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}