我有一个在旧版 html 页面上调用/渲染的 React 组件。如何让 React 调用旧版 html 页面中的 javascript 函数?
====== contents from html file ======
<script>
function buttonClicked(){
console.log('buttonClicked');
}
</script>
<div id="sample-react-component">
</div>
==================================
=======Contents from JSX =========
class Foo extends Component {
handleClick = () => {
//
// how do I call buttonClicked here?
//
}
render() {
return <button onClick={this.handleClick}>Click Me</button>;
}
}
const domContainer = document.querySelector('#sample-react-component');
ReactDOM.render(<Foo/>, domContainer);
================================================ ===
答案 0 :(得分:0)
您可以使用 window
对象使用 window.buttonClicked() 调用它。