-
Notifications
You must be signed in to change notification settings - Fork 45.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get this.prop
when use ES6 classes in React
#4425
Comments
That's not the entirety of your code. Where's the |
I think you need manually bind instance methods when using ES6. |
you are right! It worked when I call the componentDidMount () {
this.timer = setInterval(this.tick.bind(this), 50);
} Thank you all! 👻 |
@L-movingon Actually, if you are using ES6, the code block of 'componentDidMonut' method can be put inside the constructor and you don't need 'compoentDidMonut' any more. |
@cht8687 +1 You can also use the ES6 and ES7 way arrow functions and property initializers |
@cht8687 @kiki-le-singe Thanks again! |
One difference between the constructor and componentDidMount is that the constructor gets called during server rendering too. In this case @L-movingon's code uses setInterval(). If that interval gets set on the server, possible many times, then the server will become very busy. Therefore my advice is to use componentDidMount(). |
constructor(props) { } |
I'm new to React and I want to rewrite a simple react demo with ES6.
but it seem that I can't get
this.props
, here is the code.I use
"babel-loader": ^5.3.2
and"react": ^0.13.3
, thanks!The text was updated successfully, but these errors were encountered: