我在 React 中有一个组件可以显示产品的分页。我无法弄清楚为什么当我尝试运行该应用程序时会收到此错误:
Run Code Online (Sandbox Code Playgroud)React with TypeScript: Type '{ postsPerPage: number; totalPosts: number; paginate: (pageNumber: number) => void; }' is not assignable to type 'IntrinsicAttributes & ProductListProps'. Property 'postsPerPage' does not exist on type 'IntrinsicAttributes & ProductListProps'.
我的代码:
const [currentPage, setCurrentPage] = useState(1);
const [postsPerPage] = useState(10);
const indexOfLastPost = currentPage * postsPerPage;
const indexOfFirstPost = indexOfLastPost - postsPerPage;
const currentPosts = data.slice(indexOfFirstPost, indexOfLastPost);
const paginate = (pageNumber: number) => setCurrentPage(pageNumber);
return (
<>
<h1 className="headline">SHOP</h1>
<div className="total">Total: ${totalPrice}</div>
<ProductList products={data} …Run Code Online (Sandbox Code Playgroud)