Skip to content

Commit

Permalink
#18 #15 Add function fetchMoredata to utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraBergstrom committed Jun 27, 2023
1 parent 85b4618 commit 6b9671b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { axiosReq } from "../api/axiosDefaults";

export const fetchMoreData = async (resource, setResource) => {
try {
const { data } = await axiosReq.get(resource.next);
setResource((prevResource) => ({
...prevResource,
next: data.next,
results: data.results.reduce((acc, cur) => {
return acc.some((accResult) => accResult.id === cur.id)
? acc
: [...acc, cur];
}, prevResource.results),
}));
} catch (err) {}
};

0 comments on commit 6b9671b

Please sign in to comment.