Skip to content

Commit

Permalink
delete names from favorit
Browse files Browse the repository at this point in the history
all names sorted in main listafter removed from favorite
  • Loading branch information
OlhaDanylevska committed Jul 1, 2023
1 parent 2fc1e31 commit 9e94ff9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ function App() {
const sortedNames = (names, key) => {
return names.sort((a, b) => a[key].localeCompare(b[key]));
};
const [searchInput, setSearchInput] = useState("");

const initialData = sortedNames(babyNamesData, "name");
const [searchInput, setSearchInput] = useState("");
const [mainList, setMainList] = useState(initialData)

return (
Expand Down
8 changes: 7 additions & 1 deletion src/display-the-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const DisplayNames = ({ allNames, setMainList }) => {

const handleDelete = (name) => {
setFavoriteName(favoriteName.filter((babyName) => babyName.name !== name.name))
setMainList(allNames.concat(name))
let sortedNamesAfterFavorite = (names, key) => {
return names.sort((a, b) => a[key].localeCompare(b[key]));
};

const allNamesAfterFavorite = sortedNamesAfterFavorite([...allNames, name], "name");
setMainList(allNamesAfterFavorite)

}

console.log({ favoriteName })
Expand Down

0 comments on commit 9e94ff9

Please sign in to comment.