Is there any difference of declaring state, out of constructor?
I have an example of a component here:
class BurgerBuilder extends Component {
state = {
ingredients: {
salad: 0,
bacon: 0,
cheese: 0,
meat: 0
},
totalPrice: 30
};
....
}
Here I just declare a variable called state, which includes the variables of the component, but I don't call a constructor.
Where as i declare:
class BurgerBuilder extends Component {
constructor() {
super();
this.state = {
ingredients: {
salad: 0,
bacon: 0,
cheese: 0,
meat: 0
},
totalPrice: 30
};
}
....
}
I found, that I can use this.setState for both solutions and that there is no real difference in my project. Is there a best practice, on what to use where.