What are selectors in Redux?
Selectors are functions that read and return data from the store, often with memoization.
✅ Purpose:
- Centralize access to state shape
- Avoid duplication
- Optimize performance
✅ Basic selector:
const selectUser = (state) => state.user;
✅ With reselect:
import { createSelector } from 'reselect';
const selectCartItems = (state) => state.cart.items;
const selectTotalPrice = createSelector(
[selectCartItems],
(items) => items.reduce((sum, item) => sum + item.price, 0)
);
React Routing