1 回答

TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個(gè)贊
如果該console.log函數(shù)在控制臺(tái)中顯示您的代碼,則您的代碼運(yùn)行良好,現(xiàn)在您需要通過(guò)使用this.setState函數(shù)或useState鉤子來(lái)更改狀態(tài)以重新渲染組件。因?yàn)樵?ReactJS 架構(gòu)中,改變state導(dǎo)致改變界面。如果您的組件是類組件:
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.
添加回答
舉報(bào)