I would like to call in the external script, or console React components of the method
I tried to do so
componentDidMount(){
window.mwap = this;
}
but no use
please help me
The return value of ReactDOM.render()
is actually the mounted instance of the component:
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
}
inc() {
this.setState({count: this.state.count + 1});
}
render() {
return (
<div>
Count: {this.state.count}
</div>
)
}
}
const instance = ReactDOM.render(
<Counter />,
document.getElementById('app')
);
instance.inc();
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="app"></div>
If you need access to a deeply nested component, that's a bit more difficult, but this should get you started.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments