How to set React component state and props from browser

后端 未结 3 1591
遥遥无期
遥遥无期 2021-02-07 10:10

Is there a possibility to access and set the state and props of an existing React component through the browser (from inside another script or through console)?

I know t

3条回答
  •  忘掉有多难
    2021-02-07 11:02

    If you have the React devtools extension, you can access the React scope via your browser console with $r.

    First, select the component you wanna act on in the React devtools tab:

    Then, use $r to act on the component, for example read state with $r.state or set state with $r.setState({ ... }) :

提交回复
热议问题