Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

⚛️ I don't like baking app or business logic directly in components. Instead, I use useReducer hook to separate the business logic from the UI. ✅ More predictable state changes ✅ Better architecture↓

57,091 görüntüleme • 1 yıl önce •via X (Twitter)

10 Yorum

George Moller profil fotoğrafı
George Moller1 yıl önce

I've been working professionally with React for more than 8 years and I compiled all my knowledge into 100+ infographics and 70+ video tutorials just like this one. Check them out ↓

React Nuclear profil fotoğrafı
React Nuclear1 yıl önce

“Business logic” shouldn’t start with “use” because why would your business logic have anything to do with react?

JonhBoy profil fotoğrafı
JonhBoy1 yıl önce

Why not a hook for this?

anto profil fotoğrafı
anto1 yıl önce

I should probably use useReducer more often but usestate is easier for me to read

George Moller profil fotoğrafı
George Moller1 yıl önce

Fair enough, when you get used to use reducer I’d argue it’s easier to read, follow, debug and even test than useState.

skai profil fotoğrafı
skai1 yıl önce

Do you put the reducer function in the component file or in a separate file?

George Moller profil fotoğrafı
George Moller1 yıl önce

It depends really, if it gets too large yeah sure I separate that in a file, otherwise I like colocating the reducer in the component and exporting it from there to test it.

Nandakishor Pg profil fotoğrafı
Nandakishor Pg1 yıl önce

seperate file for use reducer?

Pavel Romanov profil fotoğrafı
Pavel Romanov1 yıl önce

That's how it should be done. To be honest, I would even try to move this business logic to backend whenever possible.

George Moller profil fotoğrafı
George Moller1 yıl önce

Agree whenever possible keep that in the backend!

Benzer Videolar