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

前端 未结 5 2044
暗喜
暗喜 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:10

    Open console (Firefox,Chrome) and locate any reactjs rendered DOM element or alternatively execute js script to locate it:

    document.getElementById('ROOT')
    

    Then check for element properties in object property viewer for attributes with name beginning like '__reactInternalInstace$....' expand _DebugOwner and see stateNode.

    The found stateNode will contain (if it has) 'state' and 'props' attributes which is used heavily in reactjs app.

提交回复
热议问题