selectOrdersByCustomer(customerId)
Creates a new function every time it is called but still does not need to be a problem if you have a pure component that only re renders when customerId changes:
const PureComponent = React.memo(function Component({ customerId }) { const orders = useSelector(selectOrdersByCustomer(customerId))})
Another way to memoize it is with useMemo:
function Component({ customerId }) {//not pure/memoized component const selectMyOrders = useMemo(//memoize the selector based on customerId () => selectOrdersByCustomer(customerId), [customerId] ) const orders = useSelector(selectMyOrders)}
Usually your application is wrapped in <React.StrictMode>
and in development mode the useMemo may not behave like you expect it to and creates the selector even though the customerId did not change. This is because StrictMode will try to detect memory leaks and calls hooks multiple times in development.