Last active
July 20, 2020 05:49
-
-
Save Sarav-S/e6bf14dcfa2a0a02a957b5a0c81db74f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createSelector } = require('reselect'); | |
const cart = { | |
items: [ | |
{ name: 'Item 1', value: 200, in_stock: true }, | |
{ name: 'Item 2', value: 100, in_stock: false }, | |
{ name: 'Item 3', value: 200, in_stock: true }, | |
] | |
} | |
// Using Reselect | |
const inStock = createSelector( | |
state => state.items, | |
items => items.filter(item => item.in_stock) | |
); | |
const inStockItems1 = inStock(cart); | |
const inStockItems2 = inStock(cart); | |
console.log(inStockItems1 === inStockItems2) // returns true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment