Stop useEffect React Hook re-render multiple times with Async call - Tutorial - useEffect cleanup.

preview_player
Показать описание
❗️Today I share a quick trick on how to stop unwanted responses from re-rendering a react component whose useEffect has an async function.

I ran across this problem when making an API call when a component rerendered.

---

WHO AM I: I'm Dylan, a Cloud Engineer living in Bend, Oregon. I use my background in AWS and React to make videos that enable and grow businesses.

---

🌍 My website / blog -
Рекомендации по теме
Комментарии
Автор

I am glad that you slowly show the flow of the code as it "bubbles" through. I press D this starts, it goes here, than jumps there, then there etc. Well done.

maXXik
Автор

I'm facing this problem in a project where I'm working. I couldn't solve this, but I finally understand how the clean up works. Thank you mate.

andremelo
Автор

Such a simple solution. Love it! I had to move "isCanceled" to outside the useEffect hook because I had strict mode enabled.

farid
Автор

Nice video, not sure it's my problem, but I learnt something none-the-less...had no idea the cleanup gets called the next time the useEffect is called, thanks!

matthewbeardsley
Автор

Kudos, Dylan. I tried out your code and it worked just fine. Thanks a lot.

kikevanegazz
Автор

Why are we getting red dots?!"

I feel that one 😂

DevOpsDirective
Автор

Shit man youre giving the answer on my problem that ive been struggling within hours, great video... thanks

bananas_
Автор

Thanks for making this simple to grab.

fosimuboolubo
Автор

You can use useDebounce hook instead all of these stuff.

imammahadi
Автор

Great video man. Keep making videos! Maybe make into oh who you are and what you do much shorter. Then jump right into the problem statement, why it’s a problem, where it’s applicable, and then jump directly into the solution

lacascadaobregon
Автор

It fixed the doubled "mounting" but now i want to call a function when i unmount... how can i call this only once?

raqha
Автор

I guess important thing in here is to knowing scope chain and closure.

hasanbiyik
Автор

Awesome. More videos on reactJs ... 🎊

rohit
Автор

I thought that useffect wouldn't keep the isCancelled variable on return() and that it would re-initialise it on 2nd call again (as would happen on topical variable on a normal function 2nd call) from the beggining, thanks to showing me how begginer i am on React:P

ppgg
Автор

useEffect still runs every time we type, we just don't call the alert base on a flag, does it have any problem with performance ?

thanhngo-ngci
Автор

Could u tell me the name of vscode theme, plz

huynguyenquoc
Автор

Look at that, there ARE other engineers in Bend OR

boot-strapper
Автор

This is called "race condition" right?

rodrigovazquez