Same key but different axios raw data for pagination #1679
Answered
by
shuding
skywalkerlw
asked this question in
Show and tell
-
My problem:My pagination is based on HTTP raw POST data rather than the key (url). Since the key is the same, the pagination does not work well. My approachconst url = BASE_URL + APIPath.productList + `?xx=${pageIndex}`; However, i don't think it's the good solution My question:What's the best way to do? export const useProductList = (pageIndex) => {
const url = BASE_URL + APIPath.productList ;
const params = {
h5UrlPrefix: "007",
pageSize: 5,
startIndex: pageIndex,
status: "SELL",
_type: "PC",
};
const fetcher = () =>
axios({
method: "post",
url: url,
data: params,
}).then((res) => {
return res.data;
});
console.log("pageIndex = ", pageIndex);
const { data, error } = useSWR(url, fetcher);
return {
items: data?.data?.list,
};
}; |
Beta Was this translation helpful? Give feedback.
Answered by
shuding
Nov 29, 2021
Replies: 1 comment
-
You can put the params as part of the key, too: useSWR([url, params], fetcher) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
skywalkerlw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can put the params as part of the key, too: