Chrome, Firefox debuggers not displaying the correct value for 'this' in a react app

后端 未结 3 1236
情深已故
情深已故 2021-01-06 18:57

Here\'s a bit of code, within a react component class (scaffolded using CRA 2)

  click = () => {
    console.log(this, \"hello\");
    let x = 1 + 1; //T         


        
3条回答
  •  余生分开走
    2021-01-06 19:27

    I think you need to set babel options to disable module processing. See this answer:

    How to stop babel from transpiling 'this' to 'undefined'

    In your .babelrc:

    {
      "presets": [
        [ "es2015", { "modules": false } ]
      ]
    }
    

提交回复
热议问题