Reactjs – How to cache a react lazy loaded component and prevent unnecessary unmounts and remounts
I have created a lodable component, const componentsMap = new Map(); const useCachedLazy = (importFunc, namedExport) => { if (!componentsMap.has(importFunc)) { const LazyComponent = lazy(() => importFunc().then(module => ({ default: namedExport ? module[namedExport] : module.default, })) ); componentsMap.set(importFunc, LazyComponent); }…