autobind-decorator: "Cannot set property" error on React class component method
I’m guessing I’m missing something but not sure what.
My .babelrc
:
{
"presets": ["react", "es2015", "stage-0"],
"plugins": [
"transform-decorators-legacy"
],
"env": {
"development": {
"plugins": [ "typecheck" ]
}
}
}
My webpack loader config:
{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: [ 'react-hot', 'babel?presets[]=es2015&presets[]=react&presets[]=stage-0&plugins[]=transform-decorators-legacy' ]
}
My .eslintrc
(I have no idea if both of these are needed):
"parser": "babel-eslint",
"settings": {
"import/parser": "babel-eslint",
In my React component, I use the autobind decorator:
import autobind from 'autobind-decorator';
export default class Home extends Component {
@autobind
onPress() {}
}
But I get the runtime error:
makeAssimilatePrototype.js:21 Uncaught TypeError: Cannot set property onPress of #<Home> which has only a getter
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16
met the same problem, anything else solution?