Created
October 5, 2020 09:33
-
-
Save arthurvi/3576b97d5a1ae2c89a6c333f77cf31ca to your computer and use it in GitHub Desktop.
ItemList.before.jsx
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
function ItemList() { | |
const [items, setItems] = React.useState(itemsFromServer); | |
const handleChange = React.useCallback( | |
function handleChange(id, value) { ... }, | |
[setItems] | |
); | |
async function handleSave(id) { | |
// set isSaving to true | |
await save(items[id]); | |
// set isSaving to false | |
} | |
return ( | |
<ul> | |
{Object.values(items).map(item => ( | |
<Item | |
key={item.id} | |
id={item.id} | |
value={item.value} | |
onChange={handleChange} | |
onSave={handleSave} | |
/> | |
))} | |
</ul> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment