I have two CSS files one for Light theme and other for Dark theme. How to dynamically change the style sheets ?
Here is the code i am currently using in __app.js
import React, { useState, useEffect } from "react";
import "../styles/globals.css";
import "primereact/resources/primereact.min.css";
import "primeicons/primeicons.css";
import { ThemeContext } from "../context/ThemeContext";
function MyApp({ Component, pageProps }) {
const [theme, setTheme] = useState("light");
useEffect(() => {
if (theme == "dark") {
import("primereact/resources/themes/arya-blue/theme.css");
}
if (theme == "light") {
import("primereact/resources/themes/saga-blue/theme.css");
}
}, [theme]);
return (
<ThemeContext.Provider value={[theme, setTheme]}>
<Component {...pageProps} />
</ThemeContext.Provider>
);
}
export default MyApp;
This code is working to switch from light theme to dark theme but it fails to switch from dark to light. Is their any better way to do this ?