Giống: RN dùng cùng React core nên hooks (useEffect, useLayoutEffect, useRef...) và class lifecycle (componentDidMount, componentWillUnmount) hoạt động y hệt web. Mount/update/unmount cycle giống.
Khác:
- Không có DOM event lifecycle (load, DOMContentLoaded).
- useLayoutEffect vẫn tồn tại nhưng semantics khác theo architecture: trên Old Arch (Paper), commit UIView async qua bridge nên hook chạy "trước paint" không nghiêm ngặt như web; trên New Arch (Fabric), commit đồng bộ qua C++ ShadowTree nên hook thật sự chạy trước khi UI flush ra native.
- AppState là khái niệm mới: app có thể vào background (background/inactive) khi user lock screen hoặc switch app. Nên subscribe AppState.addEventListener cho các tác vụ pause/resume (timer, video player).
- Screen focus lifecycle (qua react-navigation): useFocusEffect/useIsFocused thay vì gắn vào component mount, vì màn hình bị navigation cache (không unmount khi đẩy stack).
- Khi app bị OS kill (out of memory), không có lifecycle callback nào chạy — phải persist state vào storage chủ động.
Same: RN uses the same React core, so hooks (useEffect, useLayoutEffect, useRef...) and class lifecycle methods (componentDidMount, componentWillUnmount) behave identically. Mount/update/unmount cycles match.
Different:
- No DOM event lifecycle (load, DOMContentLoaded).
- useLayoutEffect exists, but its semantics differ by architecture: on Old Arch (Paper) the UIView commit is async over the bridge so the hook is not strictly "before paint" like web; on New Arch (Fabric) the commit is synchronous through the C++ ShadowTree, so the hook truly fires before the UI flushes to native.
- AppState is new: the app can move to background (background/inactive) when the user locks the screen or switches apps. Subscribe with AppState.addEventListener for pause/resume work (timers, video players).
- Screen focus lifecycle (via react-navigation): use useFocusEffect/useIsFocused rather than mount, because screens are cached by the navigator (they do not unmount when pushed).
- When the OS kills the app (OOM), no lifecycle callback fires — persist state proactively.