Computed Props pattern doesn't work
jscheel opened this issue · 12 comments
The "this" context appears to be different when defining a getter. See http://stackoverflow.com/questions/27440581/why-getters-dont-have-access-to-state-in-react-components.
I haven't been able to get this to work and have resorted to simple functions instead. Am I doing something wrong?
Sounds like you're using createClass
instead of the ES6 Component
class. Is that correct? If so, getters will not work.
I'm using ES6, here's a gist: https://gist.github.com/jscheel/60c97d0b1fd43df48de1
In the case of createClass
I recommend what your doing, just adding a function to the spec object. I like to prefix these types of functions with get
@jscheel I'm curious what version of React you using?
I was able to successfully demonstrate getters working on 0.13.0 in this CodePen
I'm on 0.14.0.
Curious. TBH, I have yet to update any components that do this to 0.14.
Away from the keyboard, at the moment. I won't be much help tile later.
@jscheel I have updated the codepen to use 0.14.0
, and it is still working as expected. I wonder if there are any other outside factors we can consider?
@danott Hmm, it's definitely possible. Let me investigate a bit.
@chantastic No worries!
Ok, I tracked it down. The yeoman generator-react-webpack generator is using react-hot-loader which doesn't like this for some reason.
@jscheel that's super weird. i wouldn't have guessed that it would cause issues at that level. sorry you're having issues with it.
No worries! Apparently react-hot-loader is deprecated anyways.
On Thu, Nov 5, 2015 at 11:19 PM, Michael Chan notifications@github.com
wrote:
@jscheel https://github.com/jscheel that's super weird. i wouldn't have
guessed that it would cause issues at that level. sorry you're having
issues with it.—
Reply to this email directly or view it on GitHub
#30 (comment)
.