react-use icon indicating copy to clipboard operation
react-use copied to clipboard

useCopyToClipboard should reset its status after a while

Open bebbi opened this issue 5 years ago • 6 comments

Is your feature request related to a problem? Please describe.

Problem: useCopyToClipboard has no reset functionality - once copied, the hook stays in completed state forever.

Describe the solution you'd like

This isn't regular UX that I encounter on the web. Instead the hook would rather stay in completed for a few secs then reset.

Update: some reset it based on user interaction

So how about backward-compatible:

const state = useCopyToClipboard(timeoutMS)

and/or

const { reset, ...state} = useCopyToClipboard()

and then

<div onMouseOut={reset} />

Describe alternatives you've considered

I don't know - is there a simple way to achieve this that I'm missing? Otherwise I'm considering a PR if that's welcome.

bebbi avatar Jun 04 '20 12:06 bebbi

In the PR I've settled with this format since it's the generic one:

const [state, copyToClipboard, reset] = useCopyToClipboard()

bebbi avatar Jun 04 '20 13:06 bebbi

@streamich any feedback on this or the PR?

bebbi avatar Jul 15 '20 10:07 bebbi

does this project still welcome PRs and issues @xobotyi?

bebbi avatar Nov 30 '20 16:11 bebbi

+1 on this issue.

shaohaolin avatar Feb 10 '21 19:02 shaohaolin

+1 good idea

ghost avatar Mar 17 '22 08:03 ghost

+ 1

tez123z avatar Oct 02 '22 17:10 tez123z

+1

stuart-williams avatar Nov 21 '22 08:11 stuart-williams