我知道JQuery是ReactJS中的代碼異味,因爲它遍歷整個DOM來完成它的工作。但是,我發現一些地方很難不使用它。這是我希望儘可能找到更好方法的一個例子。如何避免ReactJS中的jQuery調用
我只是想顯示或隱藏基於字段是否被填充在一個div的消息...
的javascript:
if (this.props.loginInfo.userId === ''){
$("#errorMessageDiv").attr('class', 'visible');
} else{
$("#errorMessageDiv").attr('class', 'invisible');
}
JSX:
<div id="errorMessageDiv" className="invisible">
<h1 id="credentials" className="login-error-message"> Please Enter Proper Credentials</h1>
</div>
您應該通常通過綁定類來實現。 – SLaks