Middleware
Middleware observes every action after it’s reduced and can produce additional effects. Use middleware for cross-cutting concerns that shouldn’t live inside the reducer — logging, analytics, persistence, crash reporting.PrismMiddleware Protocol
Protocol Definition
Custom Middleware
Logging Middleware
Attaching to a Store
Pass middleware as the third argument when creating a store:Store with Middleware
PrismSideEffect
PrismSideEffect is a closure-based middleware. Use it when you don’t need a dedicated type:
Inline Side Effect
.none
A no-op side effect that always returns .none:
.combine
Merge multiple side effects into one. All run concurrently for each action:
Combined Middleware
Practical Examples
Analytics Middleware
Track specific user interactions without polluting reducer logic:Analytics Middleware
Persistence Middleware
Auto-save state to disk after certain actions:Persistence Middleware
Error Reporting Middleware
Capture errors globally:Error Reporting