babel-6

Value of “this” is incorrect when debugging Babel transpiled React with Chrome Devtools

泄露秘密 提交于 2019-11-26 14:47:56
问题 I have a React application that is transpiled with Babel using the following .babelrc configuration { "presets": [ "es2015", "stage-1", "react" ], "plugins": [ "transform-decorators-legacy" ] } The application transpiles and runs fine. However, when I debug event handlers (purposely written as arrow functions), the Chrome debugger displays the value of "this" as null. Here is a sample event handler handleNext = (event) => { event.preventDefault(); this.gotoPage(this.state.page + 1); } If I