-
-
Save OnkelTem/8b8b4d8c505b768575c1ad92e5586adc to your computer and use it in GitHub Desktop.
[REACT] Map gives its closure, not need to provide more
This file contains 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
// Variant 1 | |
const ItemList = ({items, editItem}) => { | |
render ( | |
<div> | |
items.map(item => ( | |
<div onClick={(item => () => { editItem(item); })(item)}></div> | |
) | |
</div> | |
); | |
} | |
// Variant 2 | |
const ItemList = ({items, editItem}) => { | |
const openEditForm = item => () => { | |
editItem(item); | |
} | |
render ( | |
<div> | |
items.map(item => ( | |
<div onClick={() => { openEditForm(item); }}></div> | |
) | |
</div> | |
); | |
} | |
// Variant n+1 from the comments | |
const ItemList = ({items, editItem}) => { | |
render ( | |
<div> | |
{items.map(item => <div onClick={() => editItem(item)} />)} | |
</div> | |
); | |
} | |
efdee
commented
Jul 24, 2019
const ItemList = ({items, editItem}) => {
render (
<div>
{items.map(item => <div onClick={() => editItem(item)} />)}
</div>
);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment