React Redux: What & Why?
-
React Redux lets React components read data from a Redux store and dispatch actions to update it.
-
It provides hooks and components to efficiently connect Redux with React.
-
Simplifies your app’s state management and UI synchronization.
Key Concepts & API
1. <Provider>
-
Wrap your app with
<Provider>and pass the Redux store. -
Makes the store available to all nested components.
2. useSelector
-
A hook to read state from the Redux store.
-
Accepts a selector function to pick the part of the state you want.
3. useDispatch
-
A hook to dispatch actions to the store.
Complete Example: Counter
Summary
| Feature | What it does |
|---|---|
<Provider> |
Makes Redux store available to components |
useSelector |
Reads state from the Redux store |
useDispatch |
Dispatches actions to update the state |
