Skip to content

Commit

Permalink
fix fileuploader types
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-zwets authored and rkalis committed Jun 4, 2024
1 parent a0d549f commit 1a9ea23
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/FileUploader.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { useRef } from "react";

const FileUploader = ({ handleFile }) => {
interface Props {
handleFile: (fileText: string) => void
}

const FileUploader: React.FC<Props> = ({ handleFile }) => {
// Create a reference to the hidden file input element
const hiddenFileInput = useRef(null);
const hiddenFileInput = useRef(null as any);

// Programatically click the hidden file input element
// when the Button component is clicked
const handleClick = (event) => {
const handleClick = () => {
if(!hiddenFileInput?.current) return
hiddenFileInput.current.click();
};
// Call a function (passed as a prop from the parent component)
// to handle the user-selected file
const handleChange = (event) => {
const handleChange = (event: any) => {
const fileUploaded = event.target.files[0];
const fileReader = new FileReader();
fileReader.onload = function(e) {
handleFile(e.target.result);
if(!e.target?.result) return
handleFile(e.target.result as string);
}
fileReader.readAsText(fileUploaded);
};
Expand Down

0 comments on commit 1a9ea23

Please sign in to comment.