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