about summary refs log tree commit diff
path: root/client/src/Components/CopyButton.js
blob: 0ae8e833bd66549568898f033f48ff2d3e93c5c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import React, {useState} from 'react';
import copy from 'clipboard-copy';

function CopyButton(props) {
    const [copied, setCopied] = useState(false);

    const handleClick = async () => {
        await copy("https://sho.rest/" + props.hash);
        setCopied(true);
    };

    let content;
    if (copied) {
        content = <span>Link Copied!</span>;
    } else {
        content = <strong>Copy Link</strong>;
    }

    return (
        <span className="copy-text" onClick={handleClick}>{content}</span>
    )
}

export default CopyButton;