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;
LightTheme.jsx
import React from "react";
import "./light-theme.css";
const LightTheme = () => {
console.log("light theme loading");
return <></>;
};
export default LightTheme;
So what happens is when theme changes to dark the DarkTheme component loads, when theme is NOT dark, the LightTheme component loads. Right now the DarkTheme component and its css loads perfectly, however when the theme is NOT dark the LightTheme component loads BUT its css is NOT loaded.
When toggling to dark mode, works perfectly fine.
However toggling back to light, component loads but the css does not load
Full code can be found here https://codesandbox.io/s/antdesignlight-darktheme-gqwlyz?file=/src/components/light-theme.css:1369-1374