Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

TypeScript - React Native : what is the way to switch between cases in the example?

$
0
0
 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);    }  };

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>