简体   繁体   中英

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. If so, you can disable based on the index:

disabled={index}

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