Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!