当我尝试从自定义挂钩调用函数时,当屏幕加载时出现错误,提示“handleLazyLoad”不是函数。我不确定为什么 React 无法弄清楚handleLazyLoad 是一个函数,我想我可能会错误地导出它或调用它。
自定义挂钩:
import { useState } from 'react';
const useLoadInvoices = (initialPageValue, totalInvoices) => {
const [currentPage, setCurrentPage] = useState(initialPageValue);
const pageSize = 30;
const handleLazyLoad = () => {
if (currentPage * pageSize < totalInvoices) setCurrentPage(currentPage + 1);
};
const totalShownInvoices = currentPage * pageSize > totalInvoices ? totalInvoices : currentPage * pageSize;
return [totalShownInvoices, handleLazyLoad];
};
export default useLoadInvoices;
Run Code Online (Sandbox Code Playgroud)
发票屏幕组件:
import React from 'react';
import useLazyLoad from './hooks/useLazyLoad';
const InvoicesScreen = () => {
const …Run Code Online (Sandbox Code Playgroud)