react computed example
example custom computed hooks like vue, cek here https://codesandbox.io/s/custom-hooks-computed-46oxt
Computed Properties in React
function newItemsCheapestFirst(items) { return items .filter(item => item.isNew) .sort((a, b) => { if(a.price < b.price) { return -1; } else if(a.price > b.price) { return 1; } else { return 0; } }); } function NewItemsList({ items }) { return ( <ul> {newItemsCheapestFirst(items).map(item => <li key={item.id}>{item.name}, ${item.price}</li> )} </ul> ); }
Source: www.codeproject.com