From ac3a4163c1eb66ca91fc65a9c2be9610af8dc158 Mon Sep 17 00:00:00 2001 From: Pkpedram Date: Mon, 7 Feb 2022 10:04:07 +0330 Subject: [PATCH] Some Fixes --- src/components/fileInput/index.js | 34 +++++++++++++++++++++++++++++-- src/components/header/Header.js | 2 +- src/view/register/index.js | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/fileInput/index.js b/src/components/fileInput/index.js index 6b370b2..e9f778d 100644 --- a/src/components/fileInput/index.js +++ b/src/components/fileInput/index.js @@ -1,13 +1,42 @@ + import React from "react"; +import { useState, useEffect } from "react"; const FileInput = ({ title }) => { + + const [focus, setFocus] = useState('border-gray-300'); + const [selectedFile, setSelectedFile] = useState() + const [preview, setPreview] = useState(); + + useEffect(() => { + if (!selectedFile) { + setPreview(undefined) + return + } + + const objectUrl = URL.createObjectURL(selectedFile) + setPreview(objectUrl) + + // free memory when ever this component is unmounted + return () => URL.revokeObjectURL(objectUrl) + }, [selectedFile]) + + const onSelectFile = e => { + if (!e.target.files || e.target.files.length === 0) { + setSelectedFile(undefined) + return + } + + // I've kept this example simple by using the first image instead of multiple + setSelectedFile(e.target.files[0]) + } return (
- -