How do you inspect a react element's props & state in the console?

前端 未结 5 2087
暗喜
暗喜 2021-01-30 12:24

React Developer Tools give a lot of power to inspect the React component tree, and look at props, event handlers, etc. However, what I\'d really like to do is to be able to insp

5条回答
  •  春和景丽
    2021-01-30 13:04

    Using React Developer Tools you can use $r to get a reference to the selected React Component.

    The following screenshot shows you that I use React Developer Tools to select a component (Explorer) which has a state-object callednodeList. In the console I can now simply write $r.state.nodeList to reference this object in the state. Same works with the props (eg.: $r.props.path)

提交回复
热议问题