Skip to content

Instantly share code, notes, and snippets.

@yoavniran
Created March 21, 2021 12:49
Show Gist options
  • Save yoavniran/6ef8750cf6ababefa7a855981429257d to your computer and use it in GitHub Desktop.
Save yoavniran/6ef8750cf6ababefa7a855981429257d to your computer and use it in GitHub Desktop.
react-uploady usePasteUpload custom hook example
import React from "react";
import Uploady from "@rpldy/uploady";
import { usePasteUpload } from "@rpldy/upload-paste";
const ElementPaste = (props) => {
const containerRef = useRef(null);
const onPasteUpload = useCallback(({ count }) => {
console.log("ELEMENT PASTE-TO-UPLOAD files: ", count);
}, []);
const { toggle, getIsEnabled } = usePasteUpload(props, containerRef, onPasteUpload);
//toggle can be used in a button click handler to turn paste listening on/off
return <>
<div ref={containerRef}>
Click here & Paste a file
Paste is: {getIsEnabled() ? "enabled" : "disabled"}
</div>
</>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment