It's very nice that besides showing the code (even 2 or more alternative solutions of the same problem) you tell us the reasons as well, the concept behind it, why are these good/bad practices, we can learn a lot from you, Thank You!!
@blovio2 жыл бұрын
Man I could've used this video like 2 months ago, trying to find good info on this was annoying... great simple explanation.
@nemanjavucic66532 жыл бұрын
Firstly, I hit like and then start to watch
@WebDevCody2 жыл бұрын
Yeah buddyy
@JasonLayton10 ай бұрын
This is just what I needed. Thank you.
@lukor-tech2 жыл бұрын
This is something I needed and I didn't know I did.
@dcknature2 жыл бұрын
Thanks for showing us the proper way to handle this kind of situations 👍! Some apps are infamous for doing it the lazy way, plus confusing their users with ambiguous messages like: "No connection!", when the user's connection is absolutely fine 😁.
@amershboul91072 жыл бұрын
💡you can do it like that useEffect(() => { let mounted = true ( async () => { const response = await fetchData(); if ( response.data && mounted ) { setData(response.data) } })() return () => { mounted = false } },[])
@MrRe-sj2iv Жыл бұрын
I think aborting a Promise is more optimize than go around it by using mounted check.
@SahraClayton2 жыл бұрын
Another great video.
@adarsh-chakraborty2 жыл бұрын
I like these short informative videos
@tahielgomez Жыл бұрын
really helpfull. thanks!!
@StiflerNR2 жыл бұрын
Would something like this work with React + Redux + Redux-Saga + Service layer (built on open-api generator) ? In useEffect im dispatching action which go to saga => saga calls a service => service returns data and set them to ReduxStore Something like i generate AxiosCancelationToken in UseEffect --> send it to saga -> map it to service.method({ options: { cancelationToken: tokenFromUseEffect }}) and then in cleanUp function in useffect i trigger cancelationToken (Axiox.CancelToken.source().cancel()) Is this correct way ?
@WebDevCody2 жыл бұрын
I think so, I’d probably send the signal from the component inside the dispatch payload maybe so that when you unmount you can abort the signal
@aishanstha2 жыл бұрын
useEffect is called after each render and when setState is used inside of it, it will cause the component to re-render which will call useEffect and so on and so on.
@blovio2 жыл бұрын
Not if you set the dependency array (second argument of useEffect)
@rohanshahi87412 жыл бұрын
If you pass empty dependency array then it only runs on mount. And mounting and re-render is different thing.
@akilakavisinghe71892 ай бұрын
This actually doesn't currently work if you are using Next.js server actions to fetch API requests. Once a request is sent to the server the client can no longer abort it for some reason.
@niklassoderberg21682 жыл бұрын
Great! (video)
@Harish-rz4gv2 жыл бұрын
Where can I find you classroom app
@raphaelgorbach14762 жыл бұрын
Hi reletivaly new to react, how do I do this when I call a function in useEffect that does the fetching for me? Don't I then have to pass the signal as an argument so I have an object reference to that abort controller? Also woudn't this be consider bad practice since the called function would then be impure?
@WebDevCody2 жыл бұрын
If you’ve abstracted your api call out into a separate function then maybe have that function return a cancel method and the promise, that would allow your component to cancel your request at anytime and not be coupled to the api request details
@SeibertSwirl2 жыл бұрын
Good job babe!!!!!
@WebDevCody2 жыл бұрын
Thank my love!
@_Sonato Жыл бұрын
I really think you should get into the habit of using guard clauses instead of these single line if/else statements.
@vnm_89452 жыл бұрын
very nice, keep up with the good work, we' learnin' here. :D
@WebDevCody2 жыл бұрын
I’m learning too 😂
@vnm_89452 жыл бұрын
@@WebDevCody even better 😂
@orlvni2 жыл бұрын
AbortController is more reliable cause it prevents unnecessary fetching