简体   繁体   中英

Is having onClick set to null on a <button/> a bad practice in React.js?

I'm creating a custom Button component in react.js. I was wondering if having onClick={null} on a HTML button would create unnecessary event listeners that I don't need?

<button value="test" onClick={onClickHandler} onSubmit={onSubmitHandler}/>

I would use this technique if that is the case:

<button value="test" {...(onClickHandler && {onClick:onClickHandler})} {...(onSubmitHandler && {onSubmit:onSubmitHandler})}/>              

如果您希望在某个事件之后使按钮无法点击,只需确保在该事件之后将其禁用即可。

<button value="test" onClick={null} disable={valuable onevent here set it to true} />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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