I want to use reselect. I want to get my shopping cart by the ids.
reselect.ts
import { createSelector } from "reselect";import { RootState } from "../store";export const shoppingCarts = (state: RootState) => state.ShoppingCart;export const getCartById = (state: any, id: string) => createSelector( shoppingCarts, state => state.find(cart => cart.product?.id === id));
Index.tsx
const { product_id } = props; const shoppingCart = useSelector(state => getCartById(state, product_id)); console.log(shoppingCart);
console log output
[Function memoized]
how can I get the output of my function (or the json value) ?
if I make this
shoppingCart()
then I get this
undefined is not an object (evaluating 'state.ShoppingCart')