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
To set the state from your browser, stick this somewhere in your component, like in render()
:
globalSetState = function(state){this.setState(state)}.bind(this);
Note: It's important to leave off the var
, as this is what makes the defined function globally accessible.
You can now call globalSetState({x: 'y'})
in your console.
Warning: This is mad ugly, and, like console.log()
for debugging, should be deleted in your live app.