I have this list of items, each of which when clicked changes the state.ui.clickedItem to that clicked item itself. And I want to compute the items' associated Assignments record.
So I have this reselect selector:
import { createSelector } from 'reselect';
export const getAssignments = state => state.assignments
export const getClickedLineItemId = state => state.ui.clickedItem.id
export const makeClickedLineItemAssignment = () => {
return createSelector(
[
getAssignments, //Line 3
getClickedLineItemId, //Line 4
],
(
assignments,
lineItemId
) => {
console.log("should only show if the clicked item is clicked for the first time")
return assignments.filter(assignment => assignment.line_item_id === lineItemId)
}
)
}
I thought that the memo-ization would enable the behavior such that:
User clicks item A --> same Assignments immutable array && never seen before item ID --> compute the item's assignments and console.log
User clicks item B --> same as above
User clicks Item A (again) --> same Assignments array && item ID seen before --> no computation, just grab it from cache and NO console.log
that's what I expected, however, what I get is that every click recomputes the filtering and console.logging. Can anyone see any error in my Reselect code?
Thank you!