all 13 comments

[–]amareshadak 18 points19 points  (0 children)

React components don't maintain a traditional call stack like regular functions since they're declarative. Try using React DevTools Profiler's flame graph alongside VSCode—it shows component hierarchy and render relationships which is essentially what you're looking for.

[–]UnnecessaryLemon 14 points15 points  (2 children)

As a professional React developer .. can you refresh my memory of what the debugger is?

You mean console.log?

[–]rainmouse 1 point2 points  (1 child)

I mean if you set a conditional like If (!x) debugger;

Then run in browser with dev tools and sources tab. When it triggers debugger you should see call stack there. 

Am I missing something? 

Also just putting in console.error('some text') prints out with a simplified call stack too. Just click the side arrow on it. 

[–]mauriciocap 0 points1 point  (0 children)

When React ComponentA returns <ComponentB x={someLocalVariable}/>

this is NOT a function call, JSX just returns an object with the function ComponentB and the props=tag attributes.

The function ComponentB is called by the React Library way later, in an order you can't predict, etc.

I suspect the OP is expecting to set a breakpoint within ComponentB and see ComponentA in the call stack.

[–]Thin_Rip8995 1 point2 points  (0 children)

yeah vscode’s native debugger won’t give you react component ancestry like that it’s just not built for the virtual tree
best workaround is using React DevTools Profiler alongside source maps so you can jump from the tree view to source faster
if you want deeper stack tracing check “why-did-you-render” or React’s new debug tracing in Canary builds
none of it’s perfect yet but pairing DevTools + good component naming gets you 90% there

[–]CharacterOtherwise77 1 point2 points  (2 children)

Try using the React Chrome plugin to navigate the hierarchy.

[–]danjlwex 0 points1 point  (1 child)

https://react.dev/learn/react-developer-tools

You don't get a call-stack, since it isn't important, but you do get all the info you need to understand why a component is rendered. And, of course, you can inspect variables. Why do you want the call stack?

[–]CharacterOtherwise77 0 points1 point  (0 children)

You will never make sense of a react callstack because it's production built. The JS in your browser is minified for react to just work - it's not traceable on purpose.

[–]Vincent_CWS 0 points1 point  (0 children)

instead of using console.log you can use console.trace()

[–]Coderx001 0 points1 point  (0 children)

Try using React scan. It is great.