Redux :
Redux is a state management library for JavaScript applications. It provides a predictable state container to manage the state of your application in a single, centralized store.
Purpose:
To manage and share application state across components efficiently.
Key Features:
Single source of truth (a centralized store).
Pure functions called reducers handle state updates.
Dispatch actions to update the state.
Makes state predictable and debuggable.
Example Workflow in Redux:
Dispatch an action.
Reducer updates the state based on the action type.
Store holds the updated state.
React components subscribe to the state changes.
Redux Thunk :
Redux Thunk is a middleware for Redux. It allows you to write asynchronous logic (e.g., API calls) in Redux by dispatching functions (thunks) instead of plain action objects.
Purpose:
To handle asynchronous operations, such as fetching data or other side effects, while keeping Redux’s synchronous flow intact.
Key Features:
Enables dispatching functions instead of plain objects.
Provides access to dispatch and getState within thunks.
Useful for actions that require multiple steps (e.g., making an API request and dispatching different actions based on the response).
Example Workflow with Redux Thunk :
Dispatch a thunk function.
Thunk performs an asynchronous operation (e.g., API request).
Thunk dispatches one or more actions (e.g., success or error).
Reducer updates the state.