In your browser devtools, you can access the React component in the console with window.component
Try typing window.component.setState({ name: 'Kevin' });
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>React in the DOM</title> | |
| </head> | |
| <body> | |
| <div></div> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.23.1/babel.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script> | |
| <script type="text/babel"> | |
| class Welcome extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { name: "World" }; | |
| window.component = this; | |
| } | |
| render() { | |
| return <h1>{this.props.greeting}, {this.state.name}!</h1>; | |
| } | |
| } | |
| ReactDOM.render( | |
| <Welcome greeting="Hello"/>, | |
| document.getElementsByTagName('div')[0] | |
| ); | |
| </script> | |
| </body> | |
| </html> |