Reputation: 86
I need to get the number of the selected page so I can show the user certain data. I've got this pagination element:
<Pagination count={5} variant="outlined" shape="rounded" onChange={handlePagination} />
So I added onChange action with function "handlepagination" which looks like this:
function handlePagination (event) {
console.log(event.currentTarget)
}
And when I for example click button number 4, I get this output:
Can anybody help me get the number of the page, in this case, the "4" string? I tried event.currentTarget.value but that does not work...
Upvotes: 0
Views: 3956
Reputation: 71
You can use second parameter returned by the onChange
event on the Pagination component(React Material) to get the current page number like below
onChange={(event, pageNumber) => pageChangeHandler(event, pageNumber)}
pageChangeHandler(event, pageNumber = 1) {
// Your code
}
Upvotes: 7