I'm trying to create a helper method to lazily import modules with a delay in react.
This first version, when I have the path in the import fixed, it works:
import { lazy } from 'react';
export function lazyLoaderWithDealy() {
return lazy(async () => {
const [moduleExports] = await Promise.all([
import('components/SchemaEditor'),
new Promise(resolve => setTimeout(resolve, 300))
]);
return moduleExports;
});
}
But in this second example, when the path to the module comes from a variable, it doesn't work, any idea why?
import { lazy } from 'react';
export function lazyLoaderWithDealy(path) {
return lazy(async () => {
const [moduleExports] = await Promise.all([
import(path),
new Promise(resolve => setTimeout(resolve, 300))
]);
return moduleExports;
});
}