gitmyhub

re-reselect

★ 0 updated 4y ago ⑂ fork

Enhance Reselect selectors with deeper memoization and cache management.

Re-reselect Explanation

Re-reselect solves a performance problem that happens in React and Redux applications when you use selectors—functions that pull specific data from your app's state. When you call the same selector with different arguments multiple times, the standard library (Reselect) has to recalculate the result every time, even if only one small thing changed. This creates unnecessary work and can slow down your app.

The library works by keeping a collection of cached selectors instead of just one. When you call a cached selector with different arguments, it figures out which cached selector to use based on a "cache key" you define. For example, if you're fetching user data for different libraries, you might use the library name as the cache key. The first time you ask for React users, it creates and stores a selector for that. When you ask for Vue users, it creates a new one. But when you ask for React users again, it pulls from the cache instead of recalculating. This means expensive computations only happen once per unique cache key, not repeatedly.

The API is nearly identical to Reselect, so swapping one in for the other is straightforward—you just add an extra function call that tells it how to generate cache keys. This makes it useful for situations like displaying filtered or grouped data across multiple components, where you're making similar requests with slightly different parameters. Teams using Redux or similar state management systems would find this most valuable, especially when dealing with computationally expensive data transformations that happen frequently with varying inputs.

The project is built as a thin wrapper, keeping things lightweight and compatible. It lets you customize caching behavior if you need to—for instance, limiting how many selectors it stores at once—but works well out of the box for most use cases.