Created
May 3, 2022 21:30
-
-
Save bran921007/29bebf32ddd5f843fd87c4b1311db1a9 to your computer and use it in GitHub Desktop.
usePromise javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
usePromise(fetcher.states.fetched, async (onCancel) => { | |
const controller = new AbortController(); | |
onCancel(() =>{ | |
controller.abort(); | |
}); | |
const data = await fetch( | |
`/api/user/${fetcher.context}`, | |
{ | |
signal: controller.signal, | |
} | |
); | |
return (context) =>{ | |
context.data = data; | |
return "fetched"; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment