diff --git a/src/utils/utils.js b/src/utils/utils.js new file mode 100644 index 0000000..da7d56a --- /dev/null +++ b/src/utils/utils.js @@ -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) {} +};