Last active
October 2, 2020 20:38
-
-
Save joeljuca/e5854d58669fefe702e2e57bc27e136d 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 FruitList = (() => { | |
// Aqui, PRODUCT_LABELS passa a existir apenas dentro desse bloco, | |
// o que na prática funciona igual a uma closure. | |
const PRODUCT_LABELS = { | |
456: { single: "Apple", plural: "Apples" }, | |
123: { single: "Banana", plural: "Bananas" }, | |
789: { single: "Oranges", plural: "Orangess" }, | |
}; | |
// O fato do nome interno ser o mesmo do nome externo é apenas para | |
// fácil identificação. Isso poderia ser FruitListComponent, etc. | |
const FruitList = ({ fruits }) => { | |
return ( | |
<ul> | |
{fruits | |
.filter((fruit) => fruit.quantity > 0) | |
.map((fruit) => ( | |
<li> | |
{fruit.quantity === 1 | |
? PRODUCT_LABELS[fruit.id].single | |
: PRODUCT_LABELS[fruit.id].plural} | |
</li> | |
))} | |
</ul> | |
); | |
} | |
return FruitList; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment