You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Getting front end to run with fat arrow methods so that 'this' resolves.
(All file references are to `src/capstone/front`.)
1. `app.js` was defining methods using function syntax:
onEnd (end){
this.setState({
end: end
})
}
but the browser would complain at runtime that `this` wasn't defined.
2. Changed to fat arrow syntax in order to get `this` defined as per <https://stackoverflow.com/questions/33973648/react-this-is-undefined-inside-a-component-function>:
onEnd = (end) => {
this.setState({
end: end
})
}
but Parcel complained about an unexpected token (it doesn't like fat arrow syntax).
3. Discovered that we need to tell Babel to translate fat arrow syntax <https://stackoverflow.com/questions/31362292/how-to-use-arrow-functions-public-class-fields-as-class-methods>, so added `.babelrc` with React defaults *and* the command to transform class properties:
{
"presets": [
"react"
],
"plugins": [
"transform-class-properties"
]
}
Had to install a couple of packages to make this work:
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-react": "^6.24.1",
4. Commented out the calls to Chart.js stuff so that Parcel wouldn't "helpfully" try to install it along the way.
0 commit comments