maroo
Is it safe to use useFetch() inside a function?
I think useFetch, while being a macro, is named like a composable that can be used anywhere within the setup context. Since the official documentation doesn’t emphasize important caveats, it’s an easy trap to fall into.
6 replies
Is it safe to use useFetch() inside a function?
The information presented in the video is absolutely correct. However, I believe that consistently using useFetch for all data fetching and posting would enhance readability and improve error handling. As you may know, when using $fetch, it becomes difficult to perform early returns when handling errors with the .catch() chain, often leading to a larger try...catch. When wrapped in a catch, it’s harder to specifically detect and handle other errors, requiring the import and casting of types like IFetchError for more accurate error handling.
6 replies