简体   繁体   English

如何在反应中禁用特定按钮

[英]How to disable specific button in react

How can I disable a specific button, but not all, data comes from the server, there can be many buttons, but need to disable a specific one and how can now, by clicking on a button, also disable a specific button and make it so that it is always disabled if the button was pressed?如何禁用特定按钮,但不是全部,数据来自服务器,可能有很多按钮,但需要禁用特定按钮,现在如何通过单击按钮也禁用特定按钮并使其如果按下按钮,它总是被禁用?

                <div
                               className="card"
                               style={{ width: 18 + "rem" }}
                               key={`${index}`}
                           >
                               <img src={post.url} className="card-img-top" alt="..." />
                               <div className="card-body">
                                   <h5 className="card-title">{post.title}</h5>
                                   <p className="card-text">{post.content}</p>
                                   <a href="/" className="btn btn-primary">
                                       {post.category}
                                   </a>
                                   <button onClick={() => like(index)} disabled >Like</button>
                                   <h3>{post.likes} likes</h3>
                               </div>
                           </div>

I assume like(index) updates the index value to something true and false.我假设 like(index) 将索引值更新为真假。 If so, you can disable based on the index:如果是这样,您可以根据索引禁用:

disabled={index}

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

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