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

284
Visualizações
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 à 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