|
1 | | -import React, { Fragment } from 'react'; |
2 | | -import { CopyToClipboard } from 'react-copy-to-clipboard'; |
| 1 | +import React, { Fragment, useCallback, useState } from 'react'; |
3 | 2 |
|
4 | 3 | import { ClipboardIcon } from '../Icon'; |
5 | 4 | import * as selectors from '../selectors'; |
@@ -34,33 +33,27 @@ interface CopiedProps { |
34 | 33 | href: string; |
35 | 34 | } |
36 | 35 |
|
37 | | -interface CopiedState { |
38 | | - copied: boolean; |
39 | | -} |
| 36 | +const Copied: React.FC<CopiedProps> = ({ children, href }) => { |
| 37 | + const [copied, setCopied] = useState(false); |
40 | 38 |
|
41 | | -class Copied extends React.PureComponent<CopiedProps, CopiedState> { |
42 | | - public constructor(props: CopiedProps) { |
43 | | - super(props); |
44 | | - this.state = { copied: false }; |
45 | | - } |
| 39 | + const startCopy = useCallback(() => { |
| 40 | + setCopied(true); |
46 | 41 |
|
47 | | - public render() { |
48 | | - return ( |
49 | | - <p className={this.state.copied ? styles.active : styles.container}> |
50 | | - <a href={this.props.href}>{this.props.children}</a> |
51 | | - <CopyToClipboard text={this.props.href} onCopy={this.copied}> |
52 | | - <button className={styles.button}><ClipboardIcon /></button> |
53 | | - </CopyToClipboard> |
54 | | - <span className={styles.text}>Copied!</span> |
55 | | - </p> |
56 | | - ); |
57 | | - } |
| 42 | + setTimeout(() => { |
| 43 | + setCopied(false); |
| 44 | + }, 1000); |
| 45 | + }, []); |
58 | 46 |
|
59 | | - private copied = () => { |
60 | | - this.setState({ copied: true }); |
61 | | - setTimeout(() => { this.setState({ copied: false }); }, 1000); |
62 | | - } |
63 | | -} |
| 47 | + return ( |
| 48 | + <p className={copied ? styles.active : styles.container}> |
| 49 | + <a href={href}>{children}</a> |
| 50 | + <button className={styles.button} onClick={startCopy}> |
| 51 | + <ClipboardIcon /> |
| 52 | + </button> |
| 53 | + <span className={styles.text}>Copied!</span> |
| 54 | + </p> |
| 55 | + ); |
| 56 | +}; |
64 | 57 |
|
65 | 58 | const Links: React.FC = () => { |
66 | 59 | const codeUrl = useAppSelector(selectors.codeUrlSelector); |
|
0 commit comments