$ show reduxjs/react-redux
This is the official React-Redux library, providing bindings for React components to connect to a Redux store. The source code defines the core public API: `<Provider>` component, `connect()` HOC, React hooks (`useSelector`, `useDispatch`, `useStore`), `shallowEqual`, and `batch`. Under the hood, it implements a custom subscription system (`Subscription.ts`) for correct nested component update ordering, a context-based store propagation mechanism, and a variety of selector factories and memoization utilities. The library is fully typed with TypeScript, includes extensive unit and integration tests, and supports both React 18 and 19, as well as limited React Server Components. The architecture is modular but tightly coupled to Redux semantics; no external dependencies beyond React and Redux. The codebase is actively maintained, uses modern tooling (Vitest, tsup, API Extractor), and has a small set of deprecated APIs (e.g., `batch`, `connect` with `withRef`).
The LLM identified 2 files worth highlighting for reuse:
Implements a custom subscription manager (`createSubscription`) that allows nested subscriptions to be notified in a deterministic order (child before parent). It is generic and decoupled from Redux: it only requires `subscribe` and `notify` callbacks. The class handles cleanup, teardown, and state notifications. This pattern is reusable for any React context-based state management system that needs to batch updates and maintain hierarchical update order without relying on React's built-in scheduler.
A well-crafted `useSelector` hook that allows extracting data from the Redux store with a selector function. It uses `useSyncExternalStore` under the hood for safe concurrent mode compatibility. In development mode, it performs additional checks: warns if the selector returns a new reference every time (unstable result) and if the selector returns the entire root state. It also provides support for custom equality functions (defaulting to strict `===`). The hook is designed to be a template for any selector-based state management hook, and the dev-mode checks are easily adaptable to other libraries.