[英]Warning: Unknown event handler property `onClick` in React.js web app
This is the part of the code involved in the error.这是错误中涉及的代码部分。
const Balance = () => {
async function onGetBalance() {
const balance = await client.api.network.getBalance({ address: 'AcyLq3tokVpkMBMLALVMWRdVJ83TTgBUwU' });
alert('onGetBalance: ' + JSON.stringify(balance));
};
return(
<Button onClick={onGetBalance}></Button>
)
};
export default Balance;
The getbalance
function communicates with an API of an online banking app and alerts the account balance. getbalance
function 与在线银行应用程序的 API 通信并提醒帐户余额。
The original file is a Typescript file and it is this:原始文件是 Typescript 文件,它是这样的:
export const Network: React.SFC<RouterProps> = (props) => {
async function onGetBalance() {
const balance = await client.api.network.getBalance({ address: 'AcyLq3tokVpkMBMLALVMWRdVJ83TTgBUwU' });
alert('onGetBalance: ' + JSON.stringify(balance));
}
return (
<div>
<button onClick={onGetNetwork}>getNetwork</button>
</div>
);
};
The original file works, I guess it depends on props
.原始文件有效,我想这取决于
props
。 I tried with:我试过:
const Balance = (props) => {...
but it does not work.但它不起作用。 Unfortunately the only examples of how to use the API are in Typescript and I am having some difficulties and have not found other solutions by googling.
不幸的是,如何使用 API 的唯一示例在 Typescript 中,我遇到了一些困难,并且没有通过谷歌搜索找到其他解决方案。
This code looks correct(same as TypeScript file) but try debugging
or console
the value of balance
to check if you are getting any value if you aren't than your API code
has some problem and check that code.此代码看起来正确(与 TypeScript 文件相同)但尝试
debugging
或console
balance
的值以检查是否获得任何值,如果您不是API code
有一些问题并检查该代码。
look at the button element in the code.查看代码中的按钮元素。 onClick is spelt wrong and button should not start with a capital letter
onClick 拼写错误,按钮不应以大写字母开头
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.