Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Better use of lazy initialize state for Campaigns Container #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

buraksaraloglu
Copy link

@buraksaraloglu buraksaraloglu commented Aug 27, 2021

Şu anki halinde, sayfayı initial render olarak boş array'i mapliyor. İlk renderdan sonra useEffect devreye girip json'dan gelen Banners datasını state'e atıyor. Bu da 2. render'ı tetikliyor.
Güncelleme yaptığım yöntemle 2 kez render etmesini engellemek için state'in içerisine direkt json'dan gelen veriyi dolduruyoruz.

Detaylı bilgi: https://kentcdodds.com/blog/use-state-lazy-initialization-and-function-updates

@tayfunerbilen
Copy link
Owner

api requesti simüle ediyordum aslında orada sonuçta isteği gidip alması için bir süre geçecek her türlü :) belki useMemo kullanılabilir?

@buraksaraloglu
Copy link
Author

useEffect'in olayı tam olarak isteği gidip alması için geçen bir süre olarak tanımlanamaz. Yani siz state'i initialize ederken de api request atıp response'u direkt state'e yazabilirsiniz. Bu önerilmiyor çünkü state oluşturmak sync bir metod ve state oluşturulana kadar render'ı blocklamaya gerek yok. Söylediğiniz gibi useMemo şu anki durumda güzel bir kullanım yeri olurdu.
Kodu incelerken response datasını useEffect'te attığınızı görünce yazmak istedim. Videonuz varsa izlemedim o yüzden fikrinizi tam bilmiyordum. Elinize sağlık. Güzel bir çalışma olmuş.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants