-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[usePagination][material-ui] Next / Prev buttons don´t apply my onClick fuction #40101
Comments
@KatuGT Could you provide a repro? Looks like you are using Next.js, you can fork this template: https://codesandbox.io/p/devbox/material-ui-next-js-app-router-mcve-z5jyhh |
@KatuGT, the issue had to do with how the props were ordered on the button component, and that the onClick event handler from the individual item from items array was not being triggered anywhere This is what the revised code looks like: "use client";
import * as React from "react";
import usePagination from "@mui/material/usePagination";
import Link from "next/link";
import { useRouter } from "next/navigation";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
export default function CustomPaginationComponent({ count }) {
const router = useRouter();
const handlePageChange = (page, a) => {
router.push(`/?page=${page}`);
a();
};
console.log("Working");
const { items } = usePagination({
count: count,
});
return (
<nav>
<ul className="flex gap-4">
{items.map((item, index) => {
let children = null;
// console.log(item);
if (item.type === "start-ellipsis" || item.type === "end-ellipsis") {
return <span key={index}>…</span>;
} else if (item.type === "page") {
return (
<Link key={index} href={`?page=${item.page}`} {...item}>
{item.page}
</Link>
);
} else {
return (
<button
key={index}
{...item}
onClick={() => handlePageChange(item.page, item.onClick)}
>
<ArrowBackIcon />
</button>
);
}
})}
</ul>
</nav>
);
} Link since it's not formatting correctly: https://codesandbox.io/p/devbox/condescending-dijkstra-d44mk2?file=%2Fsrc%2Fapp%2FCustomPagination.tsx%3A1%2C1-52%2C1
Hope this helps |
Thanks @shihabshahriyar for looking into this ~ I will close this for now |
👋 Thanks for using MUI Core! We use GitHub issues exclusively as a bug and feature requests tracker, however, For support, please check out https://mui.com/getting-started/support/. Thanks! If you have a question on Stack Overflow, you are welcome to link to it here, it might help others. |
Genio! @shihabshahriyar Now it´s working! thank yooouuu!! |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example:
Steps:
use it enywhere you like
press the next or prev button
Current behavior 😯
that fuction should be triggered but nothing happens
Expected behavior 🤔
i need the "page" url to change
http://localhost:3000/tienda?page=4
http://localhost:3000/tienda?page=5
http://localhost:3000/tienda?page=6
...etc
the styles of the current page change perfectly and If I click any of those numbers the "link" worf just fine en the url updates
Now I need the prev and next buttons to work too
![CPT2312042010-875x810](https://private-user-images.githubusercontent.com/38865485/287868473-3b6beaef-67fd-46df-bf57-dbd10d68c748.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MDQ5NDYsIm5iZiI6MTczOTYwNDY0NiwicGF0aCI6Ii8zODg2NTQ4NS8yODc4Njg0NzMtM2I2YmVhZWYtNjdmZC00NmRmLWJmNTctZGJkMTBkNjhjNzQ4LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDA3MzA0NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFmZTFjOTQ0NTc5OGU2MDZjZDY4NWNjNmNjNzU4NGE4MjQ1ZDAxODNlYWUyMDhlZDQ0NTNkM2MxZTUwMGM3OTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.29RwXhb83Q0HWByBM9pA3c6xLKqUaTf40R-j5S5Cllg)
Context 🔦
It is a ecommerce, I could make wotk the call to the api without sending the param "page" to the url but a better user experience I want it to work that way
so any user coud send to someone else "page 2" of whatever he is looking at
Your environment 🌎
Tested on BRAVE and CHROMEnpx @mui/envinfo
The text was updated successfully, but these errors were encountered: