简体   繁体   English

React onClick不会在最初禁用的按钮上注册

[英]React onClick not registers on initially disabled button

Once facebook sdk loads i remove the disabled attr like this: this.refs.fbBtn.getDOMNode().removeAttribute('disabled'); 一旦facebook sdk加载,我就这样删除禁用的属性: this.refs.fbBtn.getDOMNode().removeAttribute('disabled'); but the onClick evt listener never gets registered because the button is disabled initially. 但是onClick evt侦听器永远不会被注册,因为该按钮最初被禁用。

<Button disabled={true} ref="fbBtn" type="button" bsStyle="primary"
        onClick={this.handleClick}>Facebook</Button>

any idea how to solve this? 任何想法如何解决这个问题?

btw should i store a disabled value in state like disabled={this.state.disabled} or by using ref? 顺便说一句,我应该以禁用状态disabled={this.state.disabled}或使用ref来存储禁用值吗?

You should absolutely do it with disabled={this.state.disabled} instead. 您绝对应该使用disabled={this.state.disabled}代替。 When you access the DOM directly, React won't know when the state of the DOM has changed. 当您直接访问DOM时,React不会知道DOM的状态何时更改。 So you need to tell React that, and the simplest way is to use state/props. 因此,您需要告诉React,最简单的方法是使用状态/属性。

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

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