正在尝试将应用内网页转换为React。应用webview自动调用Javascript函数来将访问令牌传递到网页。那么,是否可以使用相同的现有函数来传递令牌变量并将其存储为React prop呢?
HTML
<div id="app"></div>
<script>
function setToken(token){
//set token to App token prop
}
</script>JS
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
token: "",
}
}
render() {
return (
<div>
<p>{this.state.token}</p>
</div>
);
}
}
ReactDOM.render(<App />, document.querySelector("#app"))发布于 2018-11-19 18:38:24
感谢你们的帮助,我设法想出了一个解决方案(虽然不是优雅的工作)。我将ReactDom.Render()声明为一个变量,这允许我在Vanilla JS中引用React父函数。
JS
var ReactDom = ReactDOM.render(<App />, document.querySelector("#app"));HTML
function setToken(token){
ReactDom.setNewToken(token);
}https://stackoverflow.com/questions/53370176
复制相似问题