diff --git a/.changeset/rich-garlics-help.md b/.changeset/rich-garlics-help.md new file mode 100644 index 0000000..b3541c3 --- /dev/null +++ b/.changeset/rich-garlics-help.md @@ -0,0 +1,5 @@ +--- +"react-use-clipboard": patch +--- + +Add params for copying func diff --git a/README.md b/README.md index 5508f15..6894a37 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ 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 ( - ); @@ -42,13 +42,13 @@ You can reset the `isCopied` value after a certain amount of time with the `succ import useClipboard from "react-use-clipboard"; 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/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.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 ( - ); 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); },