Using a dynamic key to setState in React [duplicate]
This question already has an answer here: How to use a variable for a key in a JavaScript object literal? 12 answers Reactjs setState() with a dynamic key name? 7 answers react setState with dynamic key 1 answer From an input field I am sending the value as an argument to the function that sets state. I have multiple input fields so would like to use their name (which is equal to their state key) to then use the same function and pass in the key and value to the function that sets state. here is my code. <Modal onTextChange={(text, key) => { this.setState({ event: { key: text } }) }} /> and