finds.dev← search

// the find

dai-shi/use-context-selector

★ 2,959 · TypeScript · MIT · updated Jun 2026

React useContextSelector hook in userland

A userland implementation of a context selector hook for React, built to match how the Context API behaves under Concurrent rendering. It is aimed at library authors and teams that already keep shared state in context and need selective subscriptions without giving up concurrent-safe behavior. It is not the fastest way to cut re-renders in a typical app.

- Version 1.3 dropped the undocumented changedBits=0 mechanism that earlier versions relied on, so it no longer depends on a React internal that could change between releases.

- The README points people who only want fewer re-renders to Zustand or a useSyncExternalStore pattern. That is the right call for a library whose main risk is being picked for the wrong reason.

- The specs cover tearing, stale props, and bridging (tests 01 through 06, with snapshots), so the concurrent-rendering claims can be checked by running the suite.

- BridgeProvider and useBridgeValue pass a context value into a separate React root, which covers multi-root setups that a plain Provider cannot reach.

- Provider propagation is only stopped when children are created outside the provider or wrapped in React.memo. A wrapper that builds children inline will re-render everything, and the optimization depends on how the tree is written.

- Tearing is only avoided if every consumer reads through useContextSelector. Mixing in props or plain useContext can produce inconsistent values for a frame. The useContextUpdate escape hatch is needed for some concurrent updates, and its necessity is easy to miss, so default behavior can surprise people.

- Class components are not supported. React 17 and below have the stale props issue unless updates are wrapped in unstable_batchedUpdates, so adopting this in an older codebase means accepting those constraints.

- Consumers must install react and scheduler as peer dependencies themselves, and library authors have to document that. Because v1.3 changed the mechanism, the version pin matters more than usual.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →