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

279
Vistas
ReactNative: How to use useState with useMemo

I have a function with two parameters that returns an object(palette). The first parameter is the index for an object in palette and the second parameter controls whether to return the light or dark object.

const Theme = (index:String, DarkMode:Boolean) => {

const palette = {

background:{
light,
dark,
},

custom:{
light,
dark,
},

}
 
return(palette[index][DarkMode]);
}

Then in my react component I use this function to style my element.

const [darkMode, setDarkMode] = useState(false); // state
const bg = Theme("background",darkMode); // function

// then in my component style

backgroundColor:`${bg.background}`,

Then I have a button that toggle my darkmode state so that my theme function returns the light object instead of dark and vice versa, but the problem is the background-color of my component does not change even when the state does.

So my question is: "How do I use React.useMemo to recall my function and re-render my component when the state changes?".

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