{"id":10414,"library":"redux","title":"Redux","description":"Redux is a predictable state container for JavaScript applications. It helps manage application state consistently across different environments and simplifies testing. The current stable version is 5.0.1, which includes bug fixes and type adjustments. Redux maintains an active development cycle with regular patch releases and coordinated major updates, often alongside Redux Toolkit and React-Redux.","status":"active","version":"5.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/reduxjs/redux","tags":["javascript","redux","reducer","state","predictable","functional","immutable","hot","live","typescript"],"install":[{"cmd":"npm install redux","lang":"bash","label":"npm"},{"cmd":"yarn add redux","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While `createStore` is deprecated in v5, it's the core API for Redux directly. For new applications, the Redux team strongly recommends using `configureStore` from `@reduxjs/toolkit`.","symbol":"createStore","correct":"import { createStore } from 'redux'"},{"symbol":"combineReducers","correct":"import { combineReducers } from 'redux'"},{"symbol":"applyMiddleware","correct":"import { applyMiddleware } from 'redux'"}],"quickstart":{"code":"import { createStore } from 'redux';\n\ninterface AppState {\n  counter: number;\n}\n\ntype Action = { type: 'INCREMENT' } | { type: 'DECREMENT' };\n\nconst initialState: AppState = { counter: 0 };\n\nfunction reducer(state: AppState = initialState, action: Action): AppState {\n  switch (action.type) {\n    case 'INCREMENT':\n      return { ...state, counter: state.counter + 1 };\n    case 'DECREMENT':\n      return { ...state, counter: state.counter - 1 };\n    default:\n      return state;\n  }\n}\n\nconst store = createStore(reducer);\n\nconsole.log('Initial state:', store.getState());\n\nstore.dispatch({ type: 'INCREMENT' });\nconsole.log('State after increment:', store.getState());\n\nstore.dispatch({ type: 'DECREMENT' });\nconsole.log('State after decrement:', store.getState());\n\n// Note: For new applications, it is highly recommended to use Redux Toolkit's `configureStore`\n// and `createSlice` for a more efficient and simpler setup.","lang":"typescript","description":"This quickstart demonstrates a basic Redux store setup using `createStore`, a simple reducer, and dispatching actions. It shows how to initialize the store, retrieve the current state, and update it via actions."},"warnings":[{"fix":"Use `configureStore` from `@reduxjs/toolkit` for new store creation. Example: `import { configureStore } from '@reduxjs/toolkit'; const store = configureStore({ reducer: myReducer });`","message":"The `createStore` function is officially deprecated in Redux v5. While still functional, new applications are strongly encouraged to use `configureStore` from `@reduxjs/toolkit`.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Ensure all actions have a `type` property with a string value. E.g., `{ type: 'MY_ACTION' }`.","message":"Actions dispatched to the store MUST have a `type` property that is a string. Non-string types for `action.type` are no longer permitted.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Replace usages of `AnyAction` with `UnknownAction` in your TypeScript code.","message":"The `AnyAction` TypeScript type has been deprecated in favor of `UnknownAction` to improve type safety.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Adjust `Reducer` type definitions to use the new generic argument for preloaded state. Refer to the Redux v5 migration guide for examples.","message":"The `PreloadedState` TypeScript type has been removed and replaced by a new generic argument for the `Reducer` type.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Consider migrating your Redux application to use Redux Toolkit (`@reduxjs/toolkit`) for a better development experience and reduced boilerplate.","message":"The Redux team officially recommends using Redux Toolkit for all new Redux applications and most existing ones. Redux Toolkit simplifies common tasks, enforces best practices, and prevents common mistakes.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Ensure all dispatched actions have a `type` property set to a string value, e.g., `{ type: 'MY_ACTION' }`.","cause":"An action was dispatched without a `type` property or with `type` as `undefined`/`null`.","error":"Error: Actions may not have an undefined \"type\" property. Have you misspelled a constant?"},{"fix":"Ensure every reducer returns a valid state value (not `undefined`) for its initial state and for any action it does not handle explicitly. Always provide a default state parameter, e.g., `(state = initialState, action) => { ... }`.","cause":"A reducer returned `undefined` for its initial state, or when handling an action that it doesn't recognize.","error":"Error: The reducer \"myReducer\" returned undefined when called with an undefined state. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined."},{"fix":"Update your TypeScript code to remove references to `PreloadedState` and adjust the `Reducer` type signature to use its new generic argument for preloaded state if needed.","cause":"Attempting to use the `PreloadedState` TypeScript type, which was removed in Redux v5.","error":"TS2304: Cannot find name 'PreloadedState'."},{"fix":"Replace `AnyAction` with the new `UnknownAction` type for better type safety.","cause":"Using the `AnyAction` TypeScript type, which has been deprecated in Redux v5.","error":"'AnyAction' is deprecated."},{"fix":"Combine multiple store enhancers into a single function using `compose` before passing them to `createStore`. Example: `createStore(reducer, compose(applyMiddleware(thunk), devToolsEnhancer))`.","cause":"When calling `createStore`, multiple store enhancers were passed directly as arguments instead of being composed using `compose`.","error":"Error: Expected the last argument to be an enhancer. Instead received..."}],"ecosystem":"npm"}