Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda