File size: 481 Bytes
82d1e90 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import { useEffect, useState } from "react"
import { useFilePicker } from "use-file-picker"
export function useOpenPictureFile() {
const [picture, setPicture] = useState("")
const { openFilePicker, filesContent } = useFilePicker({
readAs: 'DataURL',
accept: 'image/*',
})
const fileData = filesContent[0]
useEffect(() => {
if (!fileData?.name) { return }
setPicture(fileData.content)
}, [fileData?.name])
return { file: picture, openFilePicker }
} |