SolidJSS
SolidJSโ€ข16mo agoโ€ข
8 replies
Luka

Sevoral Error while using AbortController

I want to allow users to abort the request. So the flow goes like this, they upload image i set imageLoading signal to true and display cancel button if they click cancel button the same function will be called and it will check if imageLoading is true if it is true I want to abort the request here is some of my code
const handleFilePreview = async (file) => { setImageLoading(true) abortController = new AbortController(); if (imageLoading()) { abortController.abort() } else { setImageLoading(true); } try { const response = await preview_image(file, props.user().profId, { signal: abortController.signal }) if (response) { batch(() => { setFile(file) setImageLoading(false) setImageUrl(response) }) } } catch (error) { console.log(error.name, error.message) if (error.name === "AbortError") { return setImageLoading(false) } } }
Was this page helpful?