Skip to content

Instantly share code, notes, and snippets.

@DZuz14
DZuz14 / index.jsx
Created July 8, 2021 23:20
Upload 6
const Upload = () => {
const [files, setFiles] = useState(null)
const inputRef = useRef()
const handleClick = () => {
inputRef.current.click()
}
const preventBubbling = (e) => {
e.stopPropagation()
@DZuz14
DZuz14 / index.jsx
Created July 8, 2021 22:56
Upload 5
const Upload = () => {
const [files, setFiles] = useState(null)
const inputRef = useRef()
const handleClick = () => {
inputRef.current.click()
}
const preventBubbling = (e) => {
e.stopPropagation()
@DZuz14
DZuz14 / index.jsx
Last active July 8, 2021 22:54
Upload 4
const Upload = () => {
const [files, setFiles] = useState(null)
const inputRef = useRef()
const handleClick = () => {
inputRef.current.click()
}
const preventBubbling = (e) => {
e.stopPropagation()
@DZuz14
DZuz14 / index.jsx
Last active July 8, 2021 22:42
Upload 3
const Upload = () => {
const inputRef = useRef()
const handleClick = () => {
inputRef.current.click()
}
const preventBubbling = (e) => {
e.stopPropagation()
e.preventDefault()
@DZuz14
DZuz14 / index.jsx
Last active July 8, 2021 22:43
Upload 2.
const Upload = () => {
const inputRef = useRef()
const handleClick = () => {
inputRef.current.click()
}
return (
<div className="Upload" css={CSS}>
<div className="inner">
@DZuz14
DZuz14 / index.jsx
Last active July 9, 2021 13:38
Upload 1. Skeleton with styling
const Upload = () => {
return (
<div className="Upload" css={CSS}>
<div className="inner">
<div className="list">
<h5>Your Files:</h5>
<ul className="files">{/* file names here. */}</ul>
</div>
import { useState, useEffect } from 'react';
export const useFileUpload = () => {
const [files, setFilesState] = useState([])
const setFiles = e => {
let filesArr = []
if (e.currentTarget?.files) {
filesArr = Array.from(e.currentTarget.files);
import { useState, useEffect } from 'react';
export const useFileUpload = () => {
const [files, setFilesState] = useState([])
const setFiles = files => {
setFilesState(Array.from(files))
}
return {
import { useState, useEffect } from 'react';
export const useFileUpload = () => {
const [files, setFiles] = useState([])
return {
files,
setFiles
}
};
@DZuz14
DZuz14 / useFileUpload.js
Created June 13, 2021 15:00
useFileUpload. skeleton
import { useState, useEffect } from 'react';
export const useFileUpload = () => {
//
};