Warm tip: This article is reproduced from stackoverflow.com, please click
reactjs

Reselect: how to cache data written to a reducer?

发布于 2020-03-27 10:17:52

I try to reselect and immediately got up the problem: data polling works. Almost every time the same data arrives in the reducer — a component rerender occurs using this data. I try to cache this data with the selector — fails — the rerender still happens. What is wrong with this code?

function getAllTickets(reducer) {
    return reducer.get('tickets');
}

export const allTicketsSelector = createSelector([getAllTickets], items => items);
Questioner
user11720503
Viewed
155
user11586836 2019-07-03 21:52

By default, the surface comparison function is used in createSelector. Want to make a deep comparison, use createSelectorCreator and your comparison function. There is an example in the documentation.