Learning React Native. Trying to convert a string into a function name. Getting an error saying "func is not a function. func is undefined". Need some help please. The end objective is to create a view with a background color and having buttons for increasing / decreasing RGB values
const [red, setRed] = useState(0);
const [green, setGreen] = useState(0);
const [blue, setBlue] = useState(0);
const setColor = (color, change) => {
// color === "red", "green", "blue"
// change === +10, -10
const colorCapitalized = color.charAt(0).toUpperCase() + color.slice(1);
var stateMethod = 'set' + colorCapitalized;
var func = window[stateMethod];
if (color + change > 255 || color + change < 0) {
return;
} else {
func(color + change);
}
};