Skip to content

Instantly share code, notes, and snippets.

View mitchellirvin's full-sized avatar

Mitchell Irvin mitchellirvin

View GitHub Profile
@mitchellirvin
mitchellirvin / cloneDataTransfer.ts
Created September 11, 2020 19:48
Deep clone a DataTransfer, to persist in asynchronous code
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/kind
enum DataTransferItemKind {
FILE = "file",
STRING = "string",
}
/**
* Returns a properly deep-cloned object of type DataTransfer. This is necessary because dataTransfer items are lost
* in asynchronous calls. See https://stackoverflow.com/questions/55658851/javascript-datatransfer-items-not-persisting-through-async-calls
* for more details.