From 551928f9fe5542dd91c9a8578124b4fb05fb9be2 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 22 Aug 2020 00:43:22 +0300 Subject: refactor: rewrite FileUpload without react-sage --- src/components/FileUpload/FileUpload.tsx | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'src/components/FileUpload') diff --git a/src/components/FileUpload/FileUpload.tsx b/src/components/FileUpload/FileUpload.tsx index 67d280d..1c05e7f 100644 --- a/src/components/FileUpload/FileUpload.tsx +++ b/src/components/FileUpload/FileUpload.tsx @@ -1,5 +1,5 @@ -import React, { useEffect } from 'react'; -import { useFilePicker, utils } from 'react-sage'; +import React, { useRef } from 'react'; +import { utils } from 'react-sage'; import Button from '@material-ui/core/Button'; import CloudUpload from '@material-ui/icons/CloudUpload'; @@ -9,20 +9,25 @@ interface PropTypes { const FileUpload: React.FC = ({ callback, children }) => { - const { files, onClick, HiddenFileInput } = useFilePicker(); + const inputRef = useRef(null); - useEffect(() => { + const handleChange = (event: React.ChangeEvent) => { + const files = event.target?.files; if (files?.length) { const file = files[0]; utils.loadFile(file).then(url => callback(url, file)); - } - }, [files, callback]); + }; + }; + + const handleClick = () => { + if (inputRef?.current) inputRef.current.click(); + }; const child = children && React.Children.toArray(children)[0]; const defaultButton = (