Skip to content

Instantly share code, notes, and snippets.

@arthurvi
Created October 5, 2020 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurvi/3576b97d5a1ae2c89a6c333f77cf31ca to your computer and use it in GitHub Desktop.
Save arthurvi/3576b97d5a1ae2c89a6c333f77cf31ca to your computer and use it in GitHub Desktop.
ItemList.before.jsx
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