Skip to content

Instantly share code, notes, and snippets.

@ctrlplusb
Created November 5, 2018 20:11
Show Gist options
  • Save ctrlplusb/51dbe544049a8d591be31ec5efedd270 to your computer and use it in GitHub Desktop.
Save ctrlplusb/51dbe544049a8d591be31ec5efedd270 to your computer and use it in GitHub Desktop.
import { select } from 'easy-peasy'; // ๐Ÿ‘ˆ import the helper
const store = createStore({
shoppingBasket: {
products: [{ name: 'Shoes', price: 123 }, { name: 'Hat', price: 75 }],
// ๐Ÿ‘‡ define your derived state
totalPrice: select(state =>
state.products.reduce((acc, cur) => acc + cur.price, 0)
)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment