Middleware is a way to enhance Redux's behavior. It provides a third-party extension point between dispatching an action, and the moment it reaches the reducer. People use Redux middleware for logging, crash reporting, talking to an asynchronous API, routing, and more.
Typically, middleware is used to:
- Log actions: Useful for debugging.
- Crash/Error reporting: Useful for logging errors.
- API calls: Useful for async actions.
- Analytics: Useful for tracking user behavior.
- Authorization: Useful for handling authentication.
It comes in between the action being dispatched and the action reaching the reducer. It can be used to perform side effects like logging, crash reporting, routing, etc.
ActionDispatch => Middleware => Reducer => Store
Types of middleware:
< Belows Genertated by GITHUB-COPILOT >
- Redux Thunk: Allows you to write action creators that return a function instead of an action. The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met. This is useful for async actions.
- Redux Saga: Uses ES6 Generators to make asynchronous flow easy to read, write and test. Sagas are implemented using a special kind of function called a Generator.
- Redux Promise: Allows you to dispatch a promise instead of an action. This is useful for async actions.
- Redux Observable: Provides an observable-based middleware for Redux. This is suitable for complex async operations that rely on cancelation.
- Redux Logger: Logs the action and state after every dispatch. This is useful for debugging.
- Redux Immutable State Invariant: Prevents accidental state mutations. This is useful for debugging.
- Redux Offline: Allows you to work offline and sync with an API when the connection is available. This is useful for offline-first apps.
- Redux Persist: Persists and rehydrates a redux store. This is useful for storing the state in local storage.
- Redux Undo: Undo/Redo functionality for Redux state. This is useful for undo/redo actions.
- Redux Form: Manages form state in Redux. This is useful for form handling.
- Redux Auth Wrapper: A wrapper for handling authentication and authorization. This is useful for protected routes.
- Redux Batched Actions: Batches multiple actions together into a single action. This is useful for reducing the number of renders.
- Redux Multi: Allows you to combine multiple stores into a single store. This is useful for code splitting.
- Redux Loop: A port of the Elm Architecture to Redux. This is useful for complex async operations.
- Redux Thunk Promise Middleware: Allows you to dispatch a promise from a thunk. This is useful for async actions.
- Redux Action Buffer: Buffers actions and releases them with a specified delay. This is useful for rate limiting.
- Redux Pack: Standardizes API response actions. This is useful for API requests.
- Redux Batch Actions: Dispatch multiple actions in a single render cycle. This is useful for reducing the number of renders.
- Redux First Router: First complete solution for routing in Redux. This is useful for routing.
- Redux Storage: Persists a Redux store. This is useful for storing the state in local storage.
- Redux Persist Immutable: Persists and rehydrates a redux store with immutable state. This is useful for storing the state in local storage with immutable state.
- Redux Persist Transform Filter: Allows you to filter the keys that are persisted. This is useful for storing only the required state in local storage.
- Redux Persist Transform Encrypt: Allows you to encrypt the state before persisting. This is useful for storing the state securely in local storage.
- Redux Persist Web Storage: Allows you to choose the web storage to use. This is useful for storing the state in a specific web storage.
- Redux Persist Cookie Storage: Allows you to choose cookies as the storage. This is useful for storing the state in cookies.
- Redux Persist Filesystem Storage: Allows you to choose the filesystem as the storage. This is useful for storing the state in the filesystem.
- Redux Persist Expo FileSystem Storage: Allows you to choose Expo FileSystem as the storage. This is useful for storing the state in Expo FileSystem.
- Redux Persist Node Storage: Allows you to choose Node storage. This is useful for storing the state in Node storage.
- Redux Persist Hapi Storage: Allows you to choose Hapi storage. This is useful for storing the state in Hapi storage.
- Redux Persist REST Storage: Allows you to choose REST storage. This is useful for storing the state in REST storage.
- Redux Persist GraphQL Storage: Allows you to choose GraphQL storage. This is useful for storing the state in GraphQL storage.
- Redux Persist Firestore Storage: Allows you to choose Firestore storage. This is useful for storing the state in Firestore storage.
- Redux Persist DynamoDB Storage: Allows you to choose DynamoDB storage. This is useful for storing the state in DynamoDB storage.
- Redux Persist S3 Storage: Allows you to choose S3 storage. This is useful for storing the state in S3 storage.
- Redux Persist Firebase Storage: Allows you to choose Firebase storage. This is useful for storing the state in Firebase storage.
- Redux Persist MongoDB Storage: Allows you to choose MongoDB storage. This is useful for storing the state in MongoDB storage.
- Redux Persist MySQL Storage: Allows you to choose MySQL storage. This is useful for storing the state in MySQL storage.
- Redux Persist PostgreSQL Storage: Allows you to choose PostgreSQL storage. This is useful for storing the state in PostgreSQL storage.
- Redux Persist SQLite Storage: Allows you to choose SQLite storage. This is useful for storing the state in SQLite storage.
- Redux Persist LocalForage Storage: Allows you to choose LocalForage storage. This is useful for storing the state in LocalForage storage.
- Redux Persist Expo SecureStore Storage: Allows you to choose Expo SecureStore storage. This is useful for storing the state in Expo SecureStore storage.
- Redux Persist SecureLS Storage: Allows you to choose SecureLS storage. This is useful for storing the state in SecureLS storage.
- Redux Persist SecureStorage Storage: Allows you to choose SecureStorage storage. This is useful for storing the state in SecureStorage storage.