I am trying to use a single handleChange
method for checkbox and then update their respective states accordingly. When I am trying to create dynamic function call its breaking. Let me know what I am doing wrong here and can utilize the same method to update check status on checkbox.
Function which is failing -
const handleChange = (event) => {
const target = event.target;
const value = target.checked;
const functionName = `set${target.name}`;
// console.log(functionName) // functionName = setisItem1 or setisItem2
functionName(value);
};
My sandbbox code - https://codesandbox.io/s/tender-hooks-guecv?file=/src/App.js[enter link description here]1