Answer the question
In order to leave comments, you need to log in
How to write a function to change an object inside state?
Guys, tell me, please.
How to pass 2 parameters a key and a value to a function so that they change the corresponding keys?
state = {
key: {
id: 1,
name: "John",
surname: "Doe",
}
};
const changeState = (name, value) => {
this.setState({
key[name] = value // не работает
});
}
changeState("name", "NoJohn");
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question