When I inspect my React code in the Chrome developer tools 'Source' tab, and I hover over the 'this.props' or even 'this' keyword / add it to watches, it shows up as undefined. Even though the code referred to executes successfully. Very annoying.... is this is bug? Is there a workaround for this?
相关问题
- How to toggle on Order in ReactJS
- Refreshing page gives Cannot GET /page_url in reac
- Adding a timeout to a render function in ReactJS
- React Native Inline style for multiple Text in sin
- Issue with React.PropTypes.func.isRequired
相关文章
- Why would we use useEffect without a dependency ar
- Is it possible to get ref of props.children?
- Stateless function components cannot be given refs
- React testing library: Test attribute / prop
- React/JestJS/Enzyme: How to test for ref function?
- Material-UI [v0.x] RaisedButton on hover styles
- Remove expo from react native
- ReactJS toLowerCase is not a function
It's
undefined
because you're inside an arrow function and by definition an arrow function doesn't own a context but it inherits the enclosing one.If you check the right menu and scroll down to the current scope you will find the closure chain of that function (one of which in your case will be the component class) that has the
this
inherited by your function.e.g.
Arrow functions doc
Due to how lexical
this
is treated by Babel in arrow functions, it cannot bethis
inside an arrow. Temporary variables like_this
,_this2
, etc. are used to imitate lexicalthis
in ES5.Transpiled code looks like:
Even though it appears like original ES6 source in debugger because of sourcemaps, it's ES5 that is evaluated. So it's
_this
local variable that needs to be debugged.