What happens, here? getPieceOfDataselector cache is invalidated on each call because of the different 3rd 'dataX' argument.

Re-reselect solution

re-reselect selectors keep a cache of reselect selectors and store/retrieve them by cacheKey.

cacheKey is by default a string or number but can be anything depending on the chosen cache strategy (see cacheObject option).

cacheKey is the output of keySelector, declared at selector initialization.

keySelector is a custom function which:

takes the same arguments as the final selector (in the example: state, itemId, 'dataX')

returns a cacheKey.

Note that the same reselect selector instance stored in cache will be used for computing data for the same cacheKey (1:1).

Back to the example, re-reselect retrieves data by querying one of the cached selectors using the 3rd argument as cacheKey, allowing cache invalidation only when state or itemId change (but not dataType):