Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

338
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda