[英]How to load utility methods dynamically in Next.js?
Doy you think it is wort to sort out logic to utility files and load dynamically to speed up site?您认为将逻辑整理到实用程序文件并动态加载以加快站点速度是不是很重要?
I have a getInvoiceDetails
method in getInvoiceDetails.tsx
file:我在
getInvoiceDetails.tsx
文件中有一个getInvoiceDetails
方法:
export default const getInvoiceDetails = (
eventId: string
) => {
I import it in an other file, in a component:我将它导入到另一个文件中,在一个组件中:
const getInvoiceDetails = dynamic(
() => import("../../Utility/BuyTicket/getInvoiceDetails")
);
and call it:并称之为:
let resp = getInvoiceDetails(
eventId
But yarn build
raise an error:但是
yarn build
会报错:
Not all constituents of type 'ComponentType<{}>' are callable.
Type 'ComponentClass<{}, any>' has no call signatures.
286 | const callInvoiceDetails = () => {
287 | callSaveData();
> 288 | let resp = getInvoiceDetails(
> Blockquote
Do you know what is wrong here?你知道这里有什么问题吗?
Next.js dynamic import is used to dynamically import React components . Next.js 动态导入用于动态导入React 组件。
Here you are trying to import a utility function - you can simply use the regular ES2020 dynamic import instead.在这里,您尝试导入实用程序 function - 您可以简单地使用常规ES2020 动态导入。
const getInvoiceDetails = await import("../../Utility/BuyTicket/getInvoiceDetails");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.