national-gold
national-gold4mo ago

useList, get current pageSize and pageIndex

Hi, how can I get the current pageSize and pageIndex, like useTable has in its tableProps but then for useList
2 Replies
kapa.ai
kapa.ai4mo ago
Hi @BlackBearFTW. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To get the current pageSize and pageIndex (which is referred to as current in refine) when using useList, you can access these values from the pagination property passed to the hook. Here's how you can do it:
const { data, pagination } = useList({
resource: "products",
pagination: {
current: 1,
pageSize: 10,
},
});

const currentPage = pagination?.current;
const currentPageSize = pagination?.pageSize;
const { data, pagination } = useList({
resource: "products",
pagination: {
current: 1,
pageSize: 10,
},
});

const currentPage = pagination?.current;
const currentPageSize = pagination?.pageSize;
The useList hook returns an object that includes the pagination property, which contains the current pagination state. You can destructure this object to access the current (equivalent to pageIndex) and pageSize values Documentation > Docs > Data > Hooks > useList > Properties > pagination (https://refine.dev/docs/data/hooks/use-list/#pagination-1). It's worth noting that if you don't specify initial values for current and pageSize, they will default to 1 and 10 respectively. You can also update these values dynamically:
const [current, setCurrent] = useState(1);
const [pageSize, setPageSize] = useState(10);

const { data } = useList({
resource: "products",
pagination: {
current,
pageSize,
},
});
const [current, setCurrent] = useState(1);
const [pageSize, setPageSize] = useState(10);

const { data } = useList({
resource: "products",
pagination: {
current,
pageSize,
},
});
This way, you can manage the pagination state in your component and pass it to useList, allowing you to update the current page or page size as needed Documentation > Docs > Data > Hooks > useList > Pagination > Retrieving the Total Row Count Part 1 (https://refine.dev/docs/data/hooks/use-list/#retrieving-the-total-row-count). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@490961337896402944> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?