Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React中的延迟负载_Reactjs_Lazy Loading - Fatal编程技术网

Reactjs React中的延迟负载

Reactjs React中的延迟负载,reactjs,lazy-loading,Reactjs,Lazy Loading,我知道延迟加载组件,如: import React, { lazy } from "react"; const Search = lazy(() => import('./components/search/Search')); 我想知道如何用lazy处理这样的导入 import { ToastContainer, toast } from 'react-toastify'; lazy期望返回{default:…}对象的承诺 如果模块不遵循此约定,则应在中间模块中将组件重新导出为def

我知道延迟加载组件,如:

import React, { lazy } from "react";
const Search = lazy(() => import('./components/search/Search'));
我想知道如何用lazy处理这样的导入

import { ToastContainer, toast } from 'react-toastify';

lazy
期望返回
{default:…}
对象的承诺

如果模块不遵循此约定,则应在中间模块中将组件重新导出为
default

export { ToastContainer as default, toast } from 'react-toastify';
或在
lazy
函数中处理:

lazy(async () => {
  const { ToastContainer } = await import('react-toastify');
  return { default: ToastContainer };
});

那么如何导入“toast”呢?我需要同时导入ToastContainer和toast。我尝试了以下方法:lazy(异步()=>{const{ToastContainer,toast}=wait import('react-toastify');返回{default:ToastContainer,toast};});但是运气不好,看起来吐司不重要。您打算在哪里使用
吐司
?该问题不包含相关代码<代码>延迟导致延迟加载组件。明白了,谢谢。