小编Vla*_*lik的帖子

使用 TypeScript 进行反应:类型不可分配给类型“IntrinsicAttributes”

我在 React 中有一个组件可以显示产品的分页。我无法弄清楚为什么当我尝试运行该应用程序时会收到此错误:

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'.
Run Code Online (Sandbox Code Playgroud)

我的代码:

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)

javascript typescript reactjs react-typescript

2
推荐指数
1
解决办法
1万
查看次数