Guest User

Untitled

a guest
Jun 12th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const handleRepoDelete = (collectionId, repoId) => {
  2.     const newCollections = collections.map(
  3.         (collection) => {
  4.             // assign collection.id, collection.repos
  5.             const {
  6.                 id,
  7.                 repos
  8.             } = collection
  9.             // if if is !== collectionId
  10.             // do noting with this
  11.             if (id !== collectionId) {
  12.                 return collection
  13.             }
  14.             // if the collection id
  15.             // is equal to id to delete
  16.             // return repos that id are different
  17.             // from the id to delete
  18.  
  19.             // this returns the new collection object
  20.             // but how this works?
  21.             return {
  22.                 ...collection,
  23.                 repos: repos.filter(
  24.                     ({ id }) => {
  25.                         id !== repoId
  26.                     }
  27.                 )
  28.             }
  29.         }
  30.     )
  31.     console.log(newCollections);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment