Skip to content

Instantly share code, notes, and snippets.

@Sarav-S
Last active July 20, 2020 05:49
Show Gist options
  • Save Sarav-S/e6bf14dcfa2a0a02a957b5a0c81db74f to your computer and use it in GitHub Desktop.
Save Sarav-S/e6bf14dcfa2a0a02a957b5a0c81db74f to your computer and use it in GitHub Desktop.
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