score:1

Accepted answer

that's because your getcountrybyid isn't actually a selector. it's a function that returns a selector.

given that you are trying to use a unique id per component, and doing filtering, you probably need to use the "factory function" form of mapstate to create a unique selector instance per component instance to get proper memoization behavior.

however, having said that, your selector can also be simplified. you don't need a filter() here, you need a find(), and that means it's also not something that really needs to be memoized. this can be simplified down to:

const getcountrybyid = createselector(
    [getcountries, (state, id) => id],
    (countries, id) => countries.find(c => c.id === id) || null
)

and then used as:

const mapstatetoprops = (state, ownprops) => {
    return  {
        country: getcountrybyid(state, ownprops.match.params.countryid)
    }
};

Related Query

More Query from same tag