How can I change getItems in useClipboard based on whether the user is copying or cutting? #7673
-
Hi - first a quick thanks to everyone working on this library. By and large I have found it excellent. When using the useClipboard hook, I don't know how onPaste can figure out whether the user cut or copied. The receiving component needs to know this as it wants to run different functions based on which operation the user performed. onCopy and onCut seem to operate after getItems every time, so I can't seem to change the getItems data based on them. As a workaround, I am using a context (copyContext), and the origin component updates the context based on whether the latest user action was copy or cut, by accessing the onCopy and onCut parameters. When pasting, I read the context before determining which function to apply. Eg:
The code works, but it really does feel like I'm missing something fundamental. Any ideas? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
We could probably support this by doing something like: getItems?: (details: {type: 'cut' | 'copy'}) => DragItem[], and passing the type for each when I think any other workaround would be hacky and involve listening for |
Beta Was this translation helpful? Give feedback.
We could probably support this by doing something like:
and passing the type for each when
getItems
is called.I think any other workaround would be hacky and involve listening for
beforecut
/beforecopy
manually on the element and communicating that up.