Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
fetch data and display on popup component

I have an array of objects file and displaying data on frontend side & I applied on a onClick function on that data which I am fetching, but the issue is when click on that button I get last array of object value but I want that specific data, data file -

 const Data = [
  {
    id: 1,
    HEXCode: "#FF6263",
    RGBACode: "rgba(255, 98, 99, 1)",
  },
  ........
 ]

my code -

const HashCode = () => {
  const [redvalue, setRedValue] = useState(Data);
  const [ButtonPopup, setButtonPopup] = useState(false);
  return (
    <Wrap>
      <Home
        code={"Hash Code"}
        link={"/"}
        link2={"/RGBCode"}
        link3={"/Gradients"}
        link4={"/TwoColorCombination"}
      />
      <Content>
        {redvalue.map((element, index) => {
          return (
            <div key={index}>
              <Button
                type="button"
                style={{ background: `${element.HEXCode}` }}
                onClick={() => setButtonPopup(true)}
              >
                {element.HEXCode}
              </Button>
              <Popup trigger={ButtonPopup} setTrigger={setButtonPopup}>
                <CopyToClipboard text={element.HEXCode}>
                  <button type="btn">{element.HEXCode}</button>
                </CopyToClipboard>
                <CopyToClipboard text={element.RGBACode}>
                  <button type="btn">{element.RGBACode}</button>
                </CopyToClipboard>
              </Popup>
            </div>
          );
        })}
      </Content>
    </Wrap>
  );
};

export default HashCode; 

Popup code -

const Popup = (props) => {
  return props.trigger ? (
    <Wrap className="popup">
      <div className="popup_inner">
        <button className="close_btn" onClick={() => props.setTrigger(false)}>
          close
        </button>
        {props.children}
      </div>
    </Wrap>
  ) : (
    ""
  );
};

export default Popup;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use index in state ButtonPopup instead boolean to check condition render of popup.

<Button
    type="button"
    style={{ background: `${element.HEXCode}` }}
    onClick={() => setButtonPopup(index)}
>
    {element.HEXCode}
</Button>

<Popup trigger={ButtonPopup === index} setTrigger={setButtonPopup}>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!