简体   繁体   English

调试vscode中的JSX

[英]Debug react JSX in vscode

I am creating a react app, and I need to see JSX at a specific point, so I started debugging using VSCode, I have my code like this: 我正在创建一个React应用,并且需要在特定位置查看JSX,所以我开始使用VSCode进行调试,我的代码如下:

 render(): JSX.Element {
        let result =  (
            <div className="footerComponent">
                <DefaultButton className={commonStyles.defaultButton} onClick= {() => this.props.saveAllSettings()} >Save Changes</DefaultButton>
                <DefaultButton className="" onClick = {() => this.setState({ dialogOpened: true})}>Discard Changes</DefaultButton>
                { this.state.dialogOpened && this.props.discardChangesDialog }
            </div>
        )
        return result
    }

I set a break point on the line : return result and I log the value in the debugging console of vscode, but it's showing this: 我在行上设置了一个断点: return result并将该值记录在vscode的调试控制台中,但显示如下:

Object {$$typeof: Symbol(react.element), type: "div", key: null, ref: null, props: Object, …}

How do I view the exact JSX? 如何查看确切的JSX? Basically, I want to know what the expression { this.state.dialogOpened && this.props.discardChangesDialog } returns. 基本上,我想知道表达式{ this.state.dialogOpened && this.props.discardChangesDialog }返回什么。

Here's what I see in the Watch window: 这是在“监视”窗口中看到的内容:

在此处输入图片说明

thanks. 谢谢。

render(): JSX.Element {
debugger;
this.state.dialogOpened;
this.props.discardChangesDialog
let result =  (
    <div className="footerComponent">
        <DefaultButton className={commonStyles.defaultButton} onClick= {() => this.props.saveAllSettings()} >Save Changes</DefaultButton>
        <DefaultButton className="" onClick = {() => this.setState({ dialogOpened: true})}>Discard Changes</DefaultButton>
        { this.state.dialogOpened && this.props.discardChangesDialog }
    </div>
)
return result
}

Just add a debugger, and open the console. 只需添加一个调试器,然后打开控制台即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM