disable cache for fetch inputimage

This commit is contained in:
Sanster
2022-03-27 13:50:41 +08:00
parent 705e12d02d
commit a6f29be662
2 changed files with 6 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
import { useCallback, useEffect, useState } from 'react'
export default function useInputImage() {
const [inputImage, setInputImage] = useState<File>()
const fetchInputImage = useCallback(() => {
const headers = new Headers()
headers.append('pragma', 'no-cache')
headers.append('cache-control', 'no-cache')
fetch('/inputimage', { headers })
.then(res => res.blob())
.then(data => {
if (data && data.type.startsWith('image')) {
const userInput = new File([data], 'inputImage')
setInputImage(userInput)
}
})
}, [setInputImage])
useEffect(() => {
fetchInputImage()
}, [fetchInputImage])
return inputImage
}