r/reactjs • u/acemarke • Oct 30 '17
Beginner's Thread / Easy Questions (week of 2017-10-29)
Looks like the last thread stayed open for quite a while, and had plenty of questions. Time for a new thread! (I should probably consider labeling these as monthly or something :) )
Soo... Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple.
The Reactiflux chat channels on Discord are another great place to ask for help as well.
22
Upvotes
View all comments
Show parent comment
3
u/acemarke Nov 03 '17
You need a constructor if you are using an ES6 class (
class MyClass extends React.Component), and you need to set an initial value for the component's state (likethis.state = {counter : 0}.However, if you have the Stage 3 Class Properties syntax enabled, you can simply declare
state = {counter : 0}as part of the body of the class definition.In either case, you would still use
this.setState()to actually update the state later on.