Hi, I’m on React but still struggle with state
and setState
. Already read the docs over the internet but there’s nothing a simple one (or maybe my brain just not good)
Please anyone can explain?
Sorry for bad english
Look at the comment for this code.
constructor(props) {
super(props);
this.state = { // This part, is this an object?
count: 0 // like equal to
// const state = {count: 0}?
};
// I believe this one below is the initialize part
// like const increment
this.increment = this.increment.bind(this)
}
// Since you already initialize it above, then you can use this one below
increment(){
//something
}
What’s the difference between these two method?
something() {
this.setState({
//something
})
}
something() {
this.setState(state => ({ // where's the state refer to? on the constructor?
//something
}));
Thank you everyone, I believe I can’t go forward until I fully understand this state and setState.