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

234
Views
TypeScript - React Native : what is the way to switch between cases in the example?
 const [darkMode, setDarkMode] = useState(false);
  const toggleDarkMode = () => setDarkMode(previousState => !previousState);

  const [locationName, setLocationName] = useState(false);
  const toggleLocationName = () => setLocationName(previousState => !previousState);

  const [diameter, setDiameter] = useState(false);
  const toggleDiameter = () => setDiameter(previousState => !previousState);

how can i do a switch case with just one function in my example ?

as you can see that the "toggleFunc" appears with different names.

"const toggleFunc = () => setDarkMode(previousState => !previousState);"
const filterFunctions = (toggleFunc: () => void, setOfVal: any) => {
switch (setOfVal) {
case darkMode: 
 return () => setDarkMode(previousState => !previousState);
 case locationName:
        return () => setLocationName(previousState => !previousState);
 case diameter:
        return () => setDiameter(previousState => !previousState);
    }
  };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I Would do it this way it's much more cleaner in my opinion

 const [darkMode, setDarkMode] = useState(false);
 const [locationName, setLocationName] = useState(false);
 const [diameter, setDiameter] = useState(false);


 const toggles = {
    diameter: () => setDiameter(p => !p),
    darkMode: () => setDarkMode(p => !p),
    locationName: () => setLocationName(p => !p),
 }

then you call each function like this

toggles.darkMode()

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