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

233
Views
TypeScript - React Native: ¿cuál es la forma de cambiar entre casos en el ejemplo?
 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);

¿Cómo puedo hacer un cambio de caso con solo una función en mi ejemplo?

como puede ver, el "toggleFunc" aparece con diferentes nombres.

 "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

Lo haría de esta manera es mucho más limpio en mi opinión.

 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), }

entonces llamas a cada función así

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!