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

158
Views
react <i> tag onClick triggers only after double Click

I intend to use the "CopyToClipboard" package so that when you click on the tag below, something is saved to the clipboard. This also works currently, but only if you double click on the tag. How do I solve it that I only have to click once and it appears directly on the clipboard?

const Card = (props: ICardProps) => {
  // // State of Clipboard
  const [clipboard, setClipboard] = useState("");
  const [copied, setCopied] = useState(false);

  const cpyClip = () => {
    setClipboard(`short.url/${props.shortUrl.shortUrl}`);
    setCopied(false);
  };

  return (
    <div>
      <div className="card-body">
        <div className="card-section">
          <div className="icon-controller">
            <CopyToClipboard
              text={clipboard}
              onCopy={() => {
                setCopied(true);
              }}
            >
              <span></span>
            </CopyToClipboard>

            <CopyToClipboard text={clipboard} onCopy={() => setCopied(copied)}>
              <i onClick={cpyClip} className="far fa-copy"></i>
            </CopyToClipboard>
          </div>
        </div>
      </div>
    </div>
  );
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because you're only setting clipboard, the string to copy, when someone clicks on the <i>.

Try something like

const Card = (props: ICardProps) => {
  const url = `short.url/${props.shortUrl.shortUrl}`;
  const [copied, setCopied] = useState(false);

  return (
    <div className="card-body">
      <div className="card-section">
        <div className="icon-controller">
          <CopyToClipboard text={url} onCopy={() => setCopied(true)}>
            <i className="far fa-copy" />{copied ? 'Copied' : null}
          </CopyToClipboard>
        </div>
      </div>
    </div>
  );
};

instead.

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!