Swish
Swish

Reputation: 359

How to use Reselect with nested selector calls

I have a large selector that loops over an array and calls a selector for each item in the array. Is there any easy way to manage this?

It looks kind of like this:

const memoizedGetPatientSymptomSeries = createSelector(
    state => getCurrentPatientId(state),
    state => displayPrefSelectors.getSymptomsToView(state), 
    (pid, selectedSymptoms) => {
        selectedSymptoms.forEach( symptom => {
            const symptomInfo = getSymptomInfoSelector(state, symptom.id)
        }
    }
)

Does anyone know how I can do this?

My only thought would be that I have to copy and paste the getSymptomInfo selector into the loop itself.

Upvotes: 3

Views: 4498

Answers (1)

Swish
Swish

Reputation: 359

I found the answer here

All it takes is creating a memoized selector that return a function which takes in the arguments you'd pass in aside from the state. Then you add that selector factory function as an argument in the original memoized selector.

Upvotes: 1

Related Questions