简体   繁体   English

在页面onload时自动在onclick上自动反应材料设计函数调用

[英]React material design function call automatically on page onload instead on onclick

I am using the React material design library. 我正在使用React材料设计库。 I added an onClick listener to <link> , but the function is called on a page load. 我在<link>添加了onClick侦听器,但是在页面加载时调用了该函数。 Why is this happening? 为什么会这样呢?

Here is my code : 这是我的代码:

<Link onClick={openBrowserWindow('http://www.stackoverflow.com')}/>

const openBrowserWindow = (url) =>{
   fin.desktop.system.openUrlWithBrowser(url);
}`

Because of the way you put the onCLick method, the function call it itself 由于您放置onCLick方法的方式,该函数本身会对其进行调用

try put the call into a function 尝试将调用放入函数中

<Link onClick = {()=>openBrowserWindow('stackoverflow.com')}/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM