Next.js Discord

Discord Forum

Been a while, are async event callbacks "safe" to use?

Unanswered
Griffon Nivernais posted this in #help-forum
Open in Discord
Griffon NivernaisOP
Haven't had to touch React and Next in a while, was wondering if using asynchronous functions for events like FocusLost to fetch data will work as intended and not have negative side-effects.

5 Replies

focus lost can be fired multiple times in a short period of time. I'll prefer using libraries like React Query or SWR to implement client-side fetching.
And it won't have any side-effects (technically)
Griffon NivernaisOP
For a relatively small project with very few dependencies (Openlayers, Zustand, Tailwind), wouldn't SWR and RQ be considered very large for this?
SWR is pretty light and easier than having a useEffect or useState to handle the fetching logic.
Also, you have to consider how to display errors if the fetch failed
Griffon NivernaisOP
Will look into, thank you so much! 💞