TS React Beginners 05 useState useEffect - useState + useEffect — state and side effects, typed

Опубликовано: 28 Май 2026
на канале: Dargslan
0

Every interactive React app starts here. We're typing them properly from day one.

In this lesson:
✓ useState T () — TS infers when it can, you specify when it can't
✓ The setter form: `setX(prev = ...)` for stale-closure safety
✓ useEffect dependencies — the array TS can't help you with
✓ Cleanup functions (subscriptions, timers, fetches)
✓ The 30-line useFetch pattern (which L08 will throw away)

You'll learn:
→ When to use the functional updater vs direct value
→ Why deps array means "run once on mount"
→ AbortController for cancelling fetches on unmount

Chapters:
00:00 The two hooks every app uses
01:30 useState — typed by inference
02:00 The setter trap (and the fix)
03:00 useEffect deps array — the rules
04:30 Cleanup is part of the API
05:30 Manual fetch with AbortController
06:00 Recap → L06 Forms + Zod

#ReactHooks #useState #useEffect #ReactDev #TypeScript