I have 5 buttons in my app which I would like to change the background color based on button states, so now when I click one button it affects all the buttons, these buttons are used to copy something in UI, each one copies something different.
Note: I know I can create five states for each button and everything will be fine but I think this is a bad solution.
Also, assume each but have its own icon and text, we should be able onclick button to change the text to COPIED and change the icon of the button too
Like this here.
Here is what I have so far
import React, { useState, useEffect, useRef } from 'react';
function Mata() {
const [isCopied, setIsCopied] = useState(0);
return (
<div className="container">
<button style={{ backgroundColor: isCopied ? '#262626' : '#F3F3F3'}} className={`btn1 ${isCopied && activeTab}`} onClick={handleBtn1}>Copy anything</button>
<button style={{ backgroundColor: isCopied ? '#262626' : '#F3F3F3'}} className={`btn2 ${isCopied && activeTab}`} onClick={handleBtn2}>Copy something</button>
<button style={{ backgroundColor: isCopied ? '#262626' : '#F3F3F3'}} className={`btn3 ${isCopied && activeTab}`} onClick={handleBtn3}>Copy Imgae</button>
<button style={{ backgroundColor: isCopied ? '#262626' : '#F3F3F3'}} className={`btn4 ${isCopied && activeTab}`} onClick={handleBtn4}>Copy text</button>
<button style={{ backgroundColor: isCopied ? '#262626' : '#F3F3F3'}} className={`btn5 ${isCopied && activeTab}`} onClick={handleBtn5}>Copy Link</button>
</div>
)
}
export default Mata
How can I create just one state eg const[isCopied, setIsCopied] = useState(); and use it in any button related to copying something in UI?
