skip to Main Content

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); }…

VIEW QUESTION

React Suspense does not load stylesheet – CSS

I have the following code. <Suspense fallback={<span />}> {theme === "dark" ? <DarkTheme /> : <LightTheme />} </Suspense> DarkTheme.jsx import React from "react"; import "./dark-theme.css"; const DarkTheme = () => { console.log("Dark theme loading..."); return <></>; }; export default DarkTheme;…

VIEW QUESTION
Back To Top
Search