Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
How to set scss $variables using js after getting it from localStorage using react

I have a scenario that I am getting color combination in hash values from the database by calling API and then storing it in localStorage for using it afterward. Is there any solution or way around getting the data from the localStorage and then using it as scss variable? I have seen implementation with --variable but I want to use $variable in the scss sheet. I tried to import js file and used jsImportor() in the webpack's sass-loader configuration. The JS file is imported successfully but I can't get localStorage in the JS file.

My JS file

let color = "#e26d26";

module.exports = {
  facebook: "#3b5998",
  twitter: "#1da1f2",
  default: color,
  white: "#fff"
}

My Scss File

@import './js-file.js';

$facebook: #3b5998;
$twitter: #1da1f2;
$default: $default;
$white: #fff;

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can assign --variable to $variable in scss file. styles.scss and styles.css

:root {
  --theme-color: #4460ac;
}
$theme-color: var(--theme-color);

And than update that color using api call directly. App.js

//Api call
    axios.get(url).then(res => {
        document.documentElement.style.setProperty(
            "--theme-color",
            res.data.Result.ThemeColor
          );
    }).catch(error=>{
            document.documentElement.style.setProperty(
            "--theme-color",
            "#4460ac"
            )
            
    })        
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!