From 9bfc3346ab4c8c1b4ab42de8f779bd9b62845b40 Mon Sep 17 00:00:00 2001 From: SangNguyen Date: Fri, 9 Apr 2021 22:44:12 +0700 Subject: [PATCH 1/4] Add params for copying --- README.md | 4 ++-- example/pages/index.js | 4 ++-- src/index.tsx | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5508f15..294d453 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ function App() { const [isCopied, setCopied] = useClipboard("Text to copy"); return ( - ); @@ -48,7 +48,7 @@ function App() { }); return ( - ); diff --git a/example/pages/index.js b/example/pages/index.js index 44c7822..12cdedd 100644 --- a/example/pages/index.js +++ b/example/pages/index.js @@ -1,13 +1,13 @@ import useClipboard from "react-use-clipboard"; export default function App() { - const [isCopied, setCopied] = useClipboard("Text to copy", { + const [isCopied, setCopied] = useClipboard({ // `isCopied` will go back to `false` after 1000ms. successDuration: 1000, }); return ( - ); diff --git a/src/index.tsx b/src/index.tsx index 48ae377..dfa0f91 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -10,9 +10,8 @@ interface IOptions { } export default function useCopyClipboard( - text: string, options?: IOptions -): [boolean, () => void] { +): [boolean, (text: string) => void] { const [isCopied, setIsCopied] = useState(false); const successDuration = options && options.successDuration; @@ -30,7 +29,7 @@ export default function useCopyClipboard( return [ isCopied, - () => { + (text: string) => { const didCopy = copy(text); setIsCopied(didCopy); }, From 9a49c6daa1fbe00580fbd4311dc6c91758458efe Mon Sep 17 00:00:00 2001 From: SangNguyen Date: Fri, 9 Apr 2021 22:49:36 +0700 Subject: [PATCH 2/4] Update test --- src/index.test.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.test.tsx b/src/index.test.tsx index 1ce8b45..364b016 100644 --- a/src/index.test.tsx +++ b/src/index.test.tsx @@ -6,10 +6,10 @@ afterEach(cleanup); test("display sucess message if the copy worked", () => { const Component = () => { - const [isCopied, setCopied] = useClipboard("Text to copy"); + const [isCopied, setCopied] = useClipboard(); return ( - ); @@ -31,12 +31,12 @@ describe("successDuration", () => { const successDuration = 1000; const Component = () => { - const [isCopied, setCopied] = useClipboard("Text to copy", { + const [isCopied, setCopied] = useClipboard({ successDuration, }); return ( - ); @@ -68,10 +68,10 @@ describe("successDuration", () => { jest.useFakeTimers(); const Component = () => { - const [isCopied, setCopied] = useClipboard("Text to copy", {}); + const [isCopied, setCopied] = useClipboard({}); return ( - ); From 39b07efd9d7deec74caa91103ea3f08b542a0852 Mon Sep 17 00:00:00 2001 From: SangNguyen Date: Fri, 9 Apr 2021 23:14:44 +0700 Subject: [PATCH 3/4] Update read me --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 294d453..6894a37 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Here's how to use `react-use-clipboard`: import useClipboard from "react-use-clipboard"; function App() { - const [isCopied, setCopied] = useClipboard("Text to copy"); + const [isCopied, setCopied] = useClipboard(); return (