Try to search your question here, if you can't find : Ask Any Question Now ?

What is the best approach to work with nested object in this.state?

HomeCategory: stackoverflowWhat is the best approach to work with nested object in this.state?
pushpa asked 2 weeks ago

I was reading the react documentation State Updates are Merged and theres a part it says when we set a object like this eg: this.setState({comments}) it completely replaces this.state.comments.

So, I wonder if the approach to change name of user object on event onChangeText is valid, because the whole object it’ll be replaced.

Is that a good practice or have side effects like bad perfomance?

example code:

this.state = {
    user:{
        name: "",
        surname: "",
    },
    isLoading: false
};
/***/
onChangeText={name => this.setState({
  user: {
    ...user,
    name
  }
})}
1 Answers
Best Answer
Amit answered 2 weeks ago
Your Answer

15 + 4 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com