“不是函数”在锚标签上使用功能的错误
我试图让锚点内的函数返回反应中分页的相应编号,但它不起作用,我真的不明白为什么我从课程中复制了代码,它传给了他而不是我。有人知道如何帮助我吗? 它给了我“pagination.jsx:16 Uncaught TypeError: onPageChange is not a function 在 onClick (pagination.jsx:16:1)" onClick 函数中。
const Pagination = (props) => {
const { itemsCount, pageSize, currentPage, onPageChange } = props;
const pagesCount = Math.ceil(itemsCount / pageSize);
if (pagesCount === 1) return null;
const pages = _.range(1, pagesCount + 1);
return (
<nav>
<ul className="pagination">
{pages.map((page) => (
<li key={page} className="page-item">
<a className="page-link" onClick={() => onPageChange(page)}>
{page}
</a>
</li>
))}
</ul>
</nav>
);
};
I tried to get the function inside the anchor to return the respective number of the pagination in react, but it doesn't work, I don't really understand why I copied a code from a course and it goes to him and not to me. would anyone know how to help me?
it gives me "pagination.jsx:16 Uncaught TypeError: onPageChange is not a function
at onClick (pagination.jsx:16:1)" in the onClick function.
const Pagination = (props) => {
const { itemsCount, pageSize, currentPage, onPageChange } = props;
const pagesCount = Math.ceil(itemsCount / pageSize);
if (pagesCount === 1) return null;
const pages = _.range(1, pagesCount + 1);
return (
<nav>
<ul className="pagination">
{pages.map((page) => (
<li key={page} className="page-item">
<a className="page-link" onClick={() => onPageChange(page)}>
{page}
</a>
</li>
))}
</ul>
</nav>
);
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须检查
onPageChange
变量中的内容。看起来它不是一个函数,甚至可能是未定义
。尝试在返回之前使用 console.log 检查它。
You have to check what's in
onPageChange
variable. Seems like it's not a function, it might be evenundefined
.Try checking it before return with console.log.