-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to copy mutable text? #37
Comments
Hi @codingbycat, thanks for the issue and sample code. What's an example of a product use case where this is especially helpful? I want to make sure I understand why this would be better than the alternative. |
Thanks for replying to me. |
If I'm understanding this correctly, it should be possible to do this with: const [isCopied, setCopied] = useClipboard({
successDuration: 1000,
});
const [textToCopy, setTextToCopy] = useState("default text to copy");
useEffect(() => {
// Get data from the server
// And then use `setTextToCopy(response)` to update the text that will be copied
}, []);
// ...
<>
<span onClick={() => setCopied(textToCopy)}>some text</span> // will be "default text to copy" if `useEffect` is not completed
</> |
This case can also meet my current situation. Maybe it would be better to use one option instead of 'useState' or 'useRef'? const [isCopied, setCopied] = useClipboard({
successDuration: 1000,
defaultValue: 'default text'
});
const getCopyText = async () => {
// Get link from the server
const linkUrl = await getServerData()
setCopied(linkUrl)
}
// ...
<>
<span onClick={getCopyText}>copy link!</span>
</> |
Hi and thanks for the lib! |
I agree... I need something like this
|
Ok this is very delayed but I made #48 which is based on #39, the PR that @sangnm0111 made. I'll leave the PR open for feedback. |
hi |
For example, api like this:
The text was updated successfully, but these errors were encountered: