我将onclick在按钮中的事件中调用异步函数。但它不起作用。是否可以在按钮 onlick 中调用异步函数?
这是代码。
过滤按钮
const FilterButton = (props) => {
return (
<div className="p-2 ">
<button className="btn btn-secondary" onClick={props.fetchInvoices}>Filter</button>
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
fetchInvoices 异步函数
fetchInvoices = async () => {
const invoices = await getInvoices(this.currentState.params);
this.props.store.dispatch(UpdateInvoices(invoices));
};
Run Code Online (Sandbox Code Playgroud)
将函数传递给组件的代码
<SearchField store = {this.props.store} fetchInvoices={this.fetchInvoices}/>
Run Code Online (Sandbox Code Playgroud) reactjs ×1