For example if I have a bunch of useState hooks such as:
const [name, setName] = useState('')
const [age, setAge] = useState(0)
const [location, setLocation] = useState('')
and a function that takes a string value such as:
const handleClick = string => console.log(string) // Name
Is there any way of dynamically choosing which state I update by passing the string value to the function call? Something along the lines of:
const handleClick = (string) => {
console.log(string) // Name
set${string}('John Doe')
}