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

226
Visualizações
react component JSX backgroundColor value not re-applied after refresh

enter image description here

so I have a <ColorPreview /> component that uses a theme value coming from the localStorage previously set by picking a color from a color picker component.

const ColorPreview = ({ colors }: any) => {
  const { theme, setTheme } = useThemeState();
  
  return (
    <>
      <div className='grid grid-cols-3 gap-4'>
        {Object.keys(theme).map((key: any, index) => {
          console.log('THEME', typeof theme[key as keyof ITheme]); //string
          return (
            <div
              key={key}
              className={clsx('overflow-hidden rounded-lg border-2', {
                ['h-62 col-span-2 row-span-2 w-52 ']: index === 0,
              })}
            >
              <div
                style={{
                  backgroundColor: `${theme[key as keyof ITheme]}`,
                }}
                className={clsx('h-28', {
                  ['!h-64']: index === 0,
                })}
              />

              <p
                className={clsx('justify-center p-2 text-base', {
                  ['!p-8']: index === 0,
                })}
              >
                {theme[key as keyof ITheme]}
              </p>
            </div>
          );
        })}
      </div>
    </>
  );
};

export default React.memo(ColorPreview);

i'm setting the theme value using a ColorPicker component that maps a color palette into the theme object so we end up with a theme object with the new color codes as follows:

  theme: {
    primary: newHexValue //#002d89,
    secondary: newHexValue //#bfd4ff,
    tertiary: newHexValue //#80aaff,
  }

the problem is that the new theme value is correctly being set up in localStorage and its values and backgroundColor is correctly being displayed on each color pick from the color picker but after Refresh of the page, the backgroundColor is not being rendered empty even though the correct color code is still persisting in the ColorPreview component as shown below.

enter image description here any help or guidance is highly appreciated...

about 4 years ago · Juan Pablo Isaza
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