Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const handleRepoDelete = (collectionId, repoId) => {
- const newCollections = collections.map(
- (collection) => {
- // assign collection.id, collection.repos
- const {
- id,
- repos
- } = collection
- // if if is !== collectionId
- // do noting with this
- if (id !== collectionId) {
- return collection
- }
- // if the collection id
- // is equal to id to delete
- // return repos that id are different
- // from the id to delete
- // this returns the new collection object
- // but how this works?
- return {
- ...collection,
- repos: repos.filter(
- ({ id }) => {
- id !== repoId
- }
- )
- }
- }
- )
- console.log(newCollections);
- }
Advertisement
Add Comment
Please, Sign In to add comment