1 回答
TA贡献1844条经验 获得超8个赞
如果该console.log函数在控制台中显示您的代码,则您的代码运行良好,现在您需要通过使用this.setState函数或useState钩子来更改状态以重新渲染组件。因为在 ReactJS 架构中,改变state导致改变界面。如果您的组件是类组件:
import React, { Component } from 'react';
~~~
class YourComponentName extends Component {
constructor() {
super();
this.state = {
result: '',
~~~
~~~
};
}
onSubmitGet = async (event) => {
event.preventDefault();
cosnt hash = document.getElementById('hash').value;
await this.state.contract.methods
.get(hash)
.call({ form: this.state.address })
.then(res => this.setState({ result: res }))
};
~~~
render() {
const { result } = this.state;
return (
<>
<button onClick={this.onSubmitGet}>GET</button>
<div>{result}</div>
</>
);
}
};
The `~~~` means some other codes. actually, with using `setState` the `<div>{result}</div>` will change and show your result.
添加回答
举报