At present, we are having no conditions to load CSS files. So, we are importing the required .scss files statically in styles.scss file that we have. But now, we have to load different scss files(themes) in the same styles.scss file based on the data we get in session storage. Can someone help me how to do it?
Thanks in advance.
2
Answers
Create separate SCSS files for each theme you want to use.
In your JavaScript code, check the session storage for the current theme data.
Based on the theme data in session storage, dynamically update the href attribute of the link element that references the styles.scss file to point to the appropriate theme SCSS file.
You will not be able to directly load .scss files into browsers. It needs to be transpiled into .css files at runtime as .scss files are used strictly for development convenience.
You also won’t be able to conditionally import .scss file within another .scss file depending on
sessionStorage
value stored in the browser.However, you can conditionally import different style (.css) files depending on
sessionStorage
values. Take at look at below example.